Two differents queries in archive page

You’ve added the filter lm_exclude_bio to pre_get_posts. So when you need to run another query you can remove the filter to get normal query. You can remove the filter like below- // Here we’re removing the filter first. Then we are running the query. remove_filter( ‘pre_get_posts’, ‘lm_exclude_bio’ ); $args = array( ‘post_type’ => ‘bio’, ‘posts_per_page’ … Read more

WordPress Find Duplicate Post By Content

Try to use the following SQL query to fetch duplicate posts: SELECT p2.* FROM wp_posts AS p1 LEFT JOIN wp_posts AS p2 ON p1.post_content = p2.post_content AND p2.ID < p1.ID AND p1.post_type = p2.post_type AND p1.post_status = p2.post_status WHERE p1.post_type=”post” AND p2.ID IS NOT NULL

How can I apply a meta query for a single custom post type in the main query?

In the case that the start_date custom field only exists for the event post type, this works: $query->set( ‘meta_query’, array( ‘relation’ => ‘OR’, array( ‘key’ => ‘start_date’, ‘compare’ => ‘NOT EXISTS’, ), array( ‘key’ => ‘start_date’, ‘value’ => $today = date( ‘Ymd’ ), ‘compare’ => ‘>=’, ), array( ‘key’ => ‘end_date’, ‘value’ => $today = … Read more

wpdb::prepare() isn’t working

The issue is that in My/SQL table names are not strings. So ‘wp_product_codes’ is being interpreted as a string instead of as an actual table. This is why you usually don’t see tables passed into wpdb::prepare() – you should know the table names as they won’t change where wpdb::prepare() is meant for data that you … Read more

Is there a conditional tag for latest post or do i need a query?

Within an ordinary WordPress Loop, the following would identify the first post in the Loop, which would be the latest if posts are ordered by date descending. global $wp_query; // might not be necessary; depends on context if (is_paged() && 0 === $wp_query->current_post) { echo ‘first-post’; } I don’t know how your custom function works … Read more

How to display all posts with today’s same month and day only?

You can achieve this with the date_query parameters added in version 3.7. To modify the main query on your posts page before it is run and apply the date_query parameters, we use the pre_get_posts action: function historical_posts_list( $query ){ if( $query->is_home() && $query->is_main_query() ){ $date_query = array( array( ‘month’ => date( ‘n’, current_time( ‘timestamp’ ) … Read more

How to show more than 5 posts?

I think you could use the posts_per_page argument in your get_posts query: $args = array( ‘child_of’ => 1 ); $categories = get_categories( $args ); foreach ($categories as $category) { echo ‘<li><a>’.$category->name.'</a>’; echo ‘<ul>’; $posts_args = array( ‘posts_per_page’ => 9, ‘category’ => $category->term_id ); foreach (get_posts($posts_args) as $post) { setup_postdata( $post ); echo ‘<li><a href=”‘.get_permalink($post->ID).'”>’.get_the_title().'</a></li>’; } … Read more