Select multiple wp_postmeta keys with single select

If you use get_post_meta() with just the first parameter ( post ID ) you’ll get an array of all the post meta for the passed ID. You’ll get more than you expect but you can then use any number of ways to get the data that you want out. $post_meta = get_post_meta( 207717 )

Modify MySQL Query Based on Dropdown Menu

You don’t need to write your own queries, just use wordpress functions. For instance, to get post by id; use get_post <form method=”POST”> <select name=”post_ID”> <option value=”21″>21</option> <option value=”22″>22</option> </select> <input type=”submit” value=”Get Selected Value” /> </form> <?php $post_id = $_POST[‘post_ID’]; if ( is_int( $post_id ) && !empty ($post_id ) ){ $post = get_post( $post_id … Read more

How to get data from WordPress site sql file

The problem is that your images reside in /wp-content/uploads/ and without this folder, everything will be restored except images and some files you have previously uploaded to the Media Library. The plugin(s) and the theme you used could be installed (uploaded and activated) again. To backup a WordPress websites you only need to backup the … Read more

add_post_meta does not respect the content

Why the content is not being respected And it’s not just add_post_meta(), but any functions like add_term_meta() and add_user_meta() that uses add_metadata(). And the reason why the value gets serialized again is because add_metadata() will automatically serialize the meta value using maybe_serialize() which (unfortunately) will serialize the value even if it’s already serialized. How to … Read more

Distinction on meta value on pre_get_posts

DISCLAIMER : Not a WordPress Expert, Just an old MySQL DBA Here is your original generated SQL SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND wp_posts.post_type=”post” AND (wp_posts.post_status=”publish” OR wp_posts.post_status=”private”) AND ( ( wp_postmeta.meta_key = ‘_position’ AND CAST(wp_postmeta.meta_value AS CHAR) > ‘0’ ) ) GROUP BY wp_posts.ID, wp_postmeta.meta_value … Read more

SQL database export-import

backup only all tables you need from localhost so your .sql file contain only the tables you need & after this go to your live server keep your databse as it the use the following cmd from unix/linux SSH to keep the old tables & only restore the new tables mysql -u username -ppassword databasename … Read more

Why doesn’t this code add a table to my database?

A key must be defined for a table by using a single column, or multiple. So on your code, you need to a line to the sql KEY id (id) – $sql = “CREATE TABLE $table_name ( id int NOT NULL AUTO_INCREMENT, feedurl text NOT NULL, category text NOT NULL, KEY id (id) );”;

Changing Table Prefix for an Existing WordPresss Site

This is pretty straightforward. You can use phpMyAdmin or MySQL Workbench to change the prefix on all the tables at once, or you can do it one-at-a-time with a tool like SequelPro. If you need to run the SQL by hand, the syntax is… RENAME TABLE `old_name` TO `new_name`; Once all the table names are … Read more