Display posts in 3 days chunk

It may be that you could use some sort of lazy loading plugin. This could be done in a custom way using admin_ajax and adding user events but there are a number of plugins available that may be able to help out. This plugin – https://wordpress.org/plugins/ajax-load-more/ – allows for the implementation of the lazy loading … Read more

Ignore post by meta value in the main query

We can try the following alternative way: Remove the two posts we select via our custom query from the main query via the pre_get_posts action Return the two posts on top of page one via the the_posts filter Lets look at possible code: add_action( ‘pre_get_posts’, function ( $q ) { remove_filter( current_filter(), __FUNCTION__ ); if … Read more

Setup of taxonomy term template pages

Added this action hook to my functions.php file: add_action( ‘pre_get_posts’, function ( $q ) { if ( !is_admin() // Only target the front end queries && $q->is_main_query() // Targets the main query only && $q->is_tax(‘course-type’) // Only target category pages ) { $q->set( ‘posts_per_page’, -1 ); } }); Then using the default loop on the … Read more

Query Ignoring ‘exclude’ Parameter?

WP_Query does not support an exclude argument. To exclude a post by ID, use post__not_in and pass it an array of IDs. Using your code above, your arguments could look like this: $args2 = array( ‘posts_per_page’ => 3, ‘post_type’ => ‘post’, ‘ignore_sticky_posts’ => 1, ‘orderby’ => ‘rand’, ‘tag__in’ => array( $first_tag, $second_tag ), ‘post__not_in’ => … Read more

WP User Query multiple AND OR query problem

I guess the search part is not working as you expect, because your search columns setup: ‘search_columns’ => ‘user_login’, is within the meta query and therefore not active. Move it out of the meta query part: $user_query = WP_User_Query( [ ‘search_columns’ = [ ‘user_login’ ], //<– array of column names … ] ); Otherwise the … Read more

Count number of published posts by type

If you prefer the $wpdb direct queries you can use something like this: global $wpdb; $count = $wpdb->get_var( “SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_type=”code” and post_status=”publish”” ); echo $count; In the sql query above change the post_type to whatever you like. This will return count of published posts under specific post type only. If you … Read more

Modify existing query and change order of posts

Was able to solve this by first registering the custom query var. https://codex.wordpress.org/Plugin_API/Filter_Reference/query_vars And then next I used the switch function: global $wp_query; switch ( $wp_query->query_vars[‘filter’] ) { case ‘random’: $recipe_args[‘orderby’] = ‘rand’; break; }

Parent / Child formatting in a list of post of a custom post type

I’m guessing the part you want to change is the actual content output area (not the nav). If so, you could do this: <?php $args = array( ‘post_type’ => ‘manual’, ‘posts_per_page’=>’-1′, ‘orderby’=>’menu_order’, ‘order’=>’asc’ ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(); $class=”parent”; $header=”h1″; if ($loop->post->post_parent !== 0) { $class=”child”; $header=”h2″; … Read more