Custom Field Query – Meta Value is Array

meta_query needs to be an array of arrays – have a look at the code sample in the Codex again. So, for your example: $args = array( ‘post_type’ => ‘pf_cookbook’, ‘meta_query’ => array( array( ‘key’ => ‘pf_cookbook_recipes’, ‘value’ => ‘5’, ‘compare’ => ‘NOT IN’, ‘type’ => ‘NUMERIC’ ) ) ); );

How to query ‘posts_per_page’ to display a different blog posts index template?

You can control what template loads for any type of query via the Template Filters. Here’s an example using home_template that checks if posts_per_page is equal to 1, and loads single.php in that case. function wpd_home_template( $home_template=”” ){ if( get_option( ‘posts_per_page’ ) == 1 ){ $home_template = locate_template( ‘single.php’, false ); } return $home_template; } … Read more

using wp_query to return posts w/ comment count > 0

While the WP_Query class has the native possibility to orderby the comment_count, it doesn’t have the same to query based on those. But when we look at the posts-table, we can see that there isn’t much we need to alter ID | post_author | post_date | post_date_gmt | post_content | post_title | post_excerpt | post_status … Read more

Injecting content with $wp_query->current_post restarts from zero on paged pages. How to inject content after X posts, regardless of pagination?

For the record, I just found a new/different way to accomplish this goal. It’s not quite the same, but it does allow me to insert a new post type after every X posts in my original loop. This is the source: https://www.gowp.com/blog/inserting-custom-posts-loop/ The method was done via the code below, which essentially injects a new … Read more

Get posts from the Main site to sub site – WordPress MultiSites Network

I use this codes to loop over the posts in the Main site: <?php $sites = wp_get_sites(); foreach($sites as $site) : // Only subsites // Connect to new multisite switch_to_blog($site[‘blog_id’]); $case_args = array( ‘post_type’ => ‘downloads’, ‘posts_per_page’ => 1, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ); $latest_cases = new WP_Query($case_args); if ( $latest_cases->have_posts() ) : … Read more