Modifing archive query affects show post count function

pre_get_posts does not explicitely changes the value in the db of posts_per_page, this value stays constant to the value set in the back end under the readings settings. pre_get_posts only changes this value before the SQL query is build in WP_Query right before the main query runs. If you need to get the exact ( … Read more

meta_value timestamp older than now

<?php $args = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘event’, ‘meta_query’ => array( array( ‘key’ => ‘event_date_end_timestamp’, ‘value’ => time(), ‘type’ => ‘numeric’, ‘compare’ => ‘<‘ ) ) ); $programs = new WP_Query($args); ?> <?php while($programs->have_posts()): $programs->the_post(); ?> <h1><?php the_title(); ?></h1> <?php endwhile; ?>

How to order WP_Query to group results?

If your naming system is consistent then simply ordering by the post name should do it: $args = array( ‘orderby’ => ‘title’, ‘order’ => ‘ASC’, ); $q = new WP_Query($args); var_dump($q->request); var_dump(wp_list_pluck($q->posts,’post_title’)); Or, as a pre_get_posts filter (assuming the main query is what we want to alter): add_action( ‘pre_get_posts’, function ($qry) { if ($qry->is_main_query()) { … Read more

How to add div blocks after certain set of post

use % to set the template(style) or you can use :nth-child(16n+1) … <?php if (have_posts()) : ?> <?php $count = 0; ?> <?php $st = 16; //after how many blocks you want to repeat the pattern <?php while (have_posts()) : the_post(); ?> <?php $count++; ?> <?php if ($count%$st == 1) : ?> <div class=”style-1″><?php the_content(); … Read more

Custom WP_Query doesn’t display all posts

All thanks to @PieterGoosen’s comment, I figured out that this issue was due to a setting within the WPML (multilingual) plugin. Under the ‘translation management’->’multilingual content setup’ tab of the plugin settings, there is a section for ‘custom posts’. In this section, my ‘publications’ post type was not set for translation, and this somehow prevented … Read more

Show posts by author of membership level (Paid Membership Pro)

$ids = get_users( array(‘role’ => ‘author’ ,’fields’ => ‘ID’) ); $contr_limit = count($ids); for($cntr=0; $cntr < $contr_limit; $cntr++){ if( pmpro_hasMembershipLevel($level_id, $ids[$cntr] ) !== true ){ unset($ids[$cntr]); } } $args = array( ‘author’ => implode(‘,’, $ids), ‘orderby’ => ‘date’, ‘order’ => ‘ASC’, );

how to use pre_gets_posts to exclude one queried ID from homepage loop

Couple of issues here You custom query should be inside your conditional statement Use get_posts which only returns the $posts property wp_reset_query() is used with query_posts which you must never ever use No need to the $post global Your code should look something like this add_action( ‘pre_get_posts’, ‘cdbz_modify_main_query’ ); function cdbz_modify_main_query( $query ) { if … Read more