negli argomenti passati negli inputs. Through get_posts() you can select a sequence of exact post using the parameter post__in in arguments over the past inputs. . The order, however, is not consistent with the sequence indicated as WordPress performs checks on the clause ORDER BY in the select statement, even though version 2.8 is available from the value of none .
Category 'MySQL / SQL'
WordPress: get_posts () and orderby
WordPress Snippet: extract meta get_posts value with ()
Working with a Custom Post Type ( CPT ) is natural to use the internal functions of WordPress to view and filter the posts of this type. , risulta comodissimo poter creare loop personali sulle proprie tipologie di post. Whether using the get_posts() is that you create an object directly WP_Query , it's very comfortable to create loops on their personal types of posts. WordPress also allows for filters for personal tassionomie, on the count, order, progressing to meta data. Useful, in fact, is the process that allows you to specify the conditions where that kind of meta data and compare it with rules.
Bachi beginning of the year: WordPress and WPML get_page_by_path update ()
The year 2012 began with a few hours of deep-debugging because of two (known) bugs pretty annoying. , con la globale (e famosa) omonima istanza $wpdb . The first, among other things quite dated, present in the core of WordPress that relates to the method update() of the class wpdb , with the global (and popular) homonymous instance $wpdb . The defect appears when you try to update a field to NULL . Despite numerous complaints, the WordPress development team does not seem to find solution to the annoying problem. Indeed, to date, the only solution is to write the SQL for your account.
MySQL: select randomly with pagination
Select a range of rows from a table at random is very simple, just use ORDER BY RAND() in our select statement. Some also prefer to use different techniques, ranging from the use of PHP to write the select special. The reason is that ORDER BY RAND() is slow because MySQL creates a temporary table with all the results and then assigns each row a random index, returning a result ordered (random)!
Very short snippet: increment a field in SQL
The latest release of WP Bannerize I introduced a new field in the table indicates how many times a banner is "clicked". To perform the operation valore = valore +1 I used in SQL:
1 | `campo` = `campo` + 1 WHERE id = id_record; UPDATE table SET `field` field `=` + 1 WHERE id = id_record; |
Very short snippet: get the number of posts, Page and Attachment
How many of you know well, the table wp_posts is used to store the WordPress post, pages and attachments. The type of the item stored is determined by the field post_type . . With select the proposal below, you can "count" individually the various types of elements in memrizzate wp_posts .
Very short trick: adjust the dates by MySQL
. You could find yourself unable to change the time setting up a Web Server or MySQL to work on a table where a field TIMESTAMP is set to ON UPDATE CURRENT_TIMESTAMP . So it becomes necessary, in the face of a select, adjust the time retrieved with the correct time zone. For example, if our server is located in Los Angeles, with a time zone 9 hours back, simply use:
1 2 | campo_timestamp , INTERVAL 9 HOUR ) AS `local_timestamp` SELECT DATE_ADD (campo_timestamp, INTERVAL HOUR 9) AS `` local_timestamp FROM mytable |
è la stessa data 9 ore avanti. The field campo_timestamp contains the actual date of the server while the alias local_timestamp is the same on 9 hours ahead.
Very short trick: duplicate or clone one or more rows in MySQL
To duplicate the whole of the contents of a table on itself just use:
1 | * FROM MYTABLE INSERT INTO SELECT * FROM MYTABLE MYTABLE |
You can also use the Clausa to WHERE if necessary:
1 | * FROM MYTABLE WHERE a = b INSERT INTO SELECT * FROM MYTABLE MYTABLE WHERE a = b |
If the table has any index or unique key, which would cause an error, you can filter the fields to be duplicated:
1 | field1 , field2 , ... ) SELECT field1 , field2 , ... FROM MYTABLE INSERT INTO mytable (field1, field2, ...) SELECT field1, field2, ... FROM MYTABLE |
Is it even possible to duplicate a record and change a value, for example duplico a field and add 1:
1 | field1 , field2 , ... ) SELECT ( field1 + 1 ) , field2 , ... FROM MYTABLE INSERT INTO mytable (field1, field2, ...) SELECT (field1 + 1), field2, ... FROM MYTABLE |






Latest Comments
Subject : very helpful indeed! I tried it and it is just what I needed. Now I wonder how do I get ...
vik : With strategic help!
Pepper : Hi there, I do not know if you're one of the creators of the WP plugin Bannerize. I have spotted a ...
Rosanna : Can anyone tell me how do I delete the Snap Shots window that opens automatically when I ...
blessed Maresca : I can not download any skypemote me spiegaaa