the_date() not working

See this special note about using the `the_date’ SPECIAL NOTE: When there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post (that is, the first instance of the_date()). To repeat the date for posts published under the same day, you should use the Template … Read more

Query multiple meta key values?

I feel like there’s an AND/OR confusion going on here. The queries in the OP will only return posts which have both key1 = ‘value1’ AND key2 = ‘value2’. Most WP plugins (that I know of, anyway) do not store multiple values in postmeta, for the same post, using the same key. If what you … Read more

What SQL Query to do a simple find and replace

The table where your URL is saved is wp_options. You should do an update on the columns that use the URL for your site: UPDATE TABLE wp_options SET option_value = “new domain” WHERE option_name = “siteurl” UPDATE TABLE wp_options SET option_value = “new domain” WHERE option_name = “home” I might be missing some value, but … Read more

How can I create a meta_query with an array as meta_field?

Feeding the query an array of possible values If the value in the database is a string and you want to feed the query several values: $args = array( ‘post_type’ => ‘news’, ‘meta_query’ => array( array( ‘key’ => ‘topics’, ‘value’ => array ( ‘sports’, ‘nonprofit’, ‘community’ ), ‘compare’ => ‘IN’ ) ) ); Searching for … Read more

Pagination not working with custom loop

I’ve run into this problem with PageNavi before. My solution is to hijack the $wp_query variable temporarily and then reassign it after closing the loop. An exmaple: <?php $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $args=array( ‘post_type’=>’post’, ‘cat’ => 6, ‘posts_per_page’ => 5, ‘paged’=>$paged ); $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query($args); /* … Read more

When should you use WP_Query vs query_posts() vs get_posts()?

query_posts() is overly simplistic and a problematic way to modify the main query of a page by replacing it with new instance of the query. It is inefficient (re-runs SQL queries) and will outright fail in some circumstances (especially often when dealing with posts pagination). Any modern WP code should use more reliable methods, like … Read more