simple sql query on wp_postmeta very slow

wp_postmeta has inefficient indexes. The published table (see Wikipedia) is CREATE TABLE wp_postmeta ( meta_id bigint(20) unsigned NOT NULL AUTO_INCREMENT, post_id bigint(20) unsigned NOT NULL DEFAULT ‘0’, meta_key varchar(255) DEFAULT NULL, meta_value longtext, PRIMARY KEY (meta_id), KEY post_id (post_id), KEY meta_key (meta_key) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; The problems: The AUTO_INCREMENT provides no benefit; in fact … Read more

what are the numbers between curly brackets in search query

Those are placeholders for % signs. If you’re sending % in the value to be compared against yourself, you’ll notice it transforming ‘%test%’ into wp_posts.post_title LIKE ‘{30d0e4b86a2a793010a75740f60810aff6b57f6d18edc10be7ca6dc158e40c06}\{30d0e4b86a2a793010a75740f60810aff6b57f6d18edc10be7ca6dc158e40c06}11{30d0e4b86a2a793010a75740f60810aff6b57f6d18edc10be7ca6dc158e40c06}\{30d0e4b86a2a793010a75740f60810aff6b57f6d18edc10be7ca6dc158e40c06}’ when you look at $query->request. The Query at the database side will have %. I haven’t looked into why exactly and where it is done, but I’ve noticed … Read more

Reversing the order of posts AFTER the query is performed

I figured out what I was doing wrong. A simple beginners mistake. Array_reverse was working properly, but I wasn’t then reassigning the reversed array back to the $home_shows WP_Query, hence not seeing any change. Here is the answer, and my revised code. <?php $args = array( ‘post_type’ => ‘show’, ‘posts_per_page’ => 5, ‘order’ => ‘DESC’, … Read more

Get Terms by IDs with IDs order

So I believe the question is how to get the terms back in the order of the Ids you’ve provided – which might not be sorted ascending or descending, but a random order instead. Surprisingly, I think there’s a shortcut for that in WP – who knew? This, I believe, is what you want to … Read more

How to get comments by post ID?

You can use get_comments. Function Reference/get comments $args = array(‘cat’ => ‘home’,’post_type’ => ‘post’)); $post_obj = new WP_Query($args); while($post_obj->have_posts() ) : $post_obj->the_post(); //display comments $comments = get_comments(array( ‘post_id’ => $post->ID, ‘number’ => ‘2’ )); foreach($comments as $comment) { //format comments } endwhile;