Widgets in the loop if active

Think about what is happening. You run the_post(); which sets $post to the first post in the Loop, but you don’t use that post if your sidebar is active. Then the Loop continues and $post gets set to the second post in the Loop. You’ve lost your first post. I don’t see why that first … Read more

Display all posts that use a custom taxonomy

I think your problem is here: ‘terms’ => array($clients_terms->slug) You define $clients_terms like so: $clients_terms = get_terms(‘clients’); …which will return an array of objects. But you try to access it as an object in your query args. That should be producing some kind of PHP notice? (Trying to get property of non-object, or something?) Try … Read more

Combine the results of two loops [closed]

Yes it is. First you have to combine the results in one array: $all_posts = array_merge( $related->posts, $features->posts ); Now, let’s sort the array items by date: usort( $all_posts, function( $a, $b ) { return strcmp( $b->post_date, $a->post_date ); } ); Finally, do the loop: global $post; foreach ( $all_posts as $post ) { setup_postdata( … Read more

Why does `inclusive` not work in this wordpress loop?

Edit 3 Now, combine Edits 1 and 2: ‘date_query’ = > array( array( ‘before’ = > strtotime( get_the_date() ), ‘inclusive’ = > true, ) ) Edit 2 You don’t have your inclusive parameter inside the correct array. Change this: ‘date_query’ = > array( array( ‘before’ = > get_the_date() ), ‘inclusive’ = > true, ) …to … Read more

Only display sticky post or latest post in custom loop

You can adapt your first loop to either show a sticky post or the latest post in the following manner: PLEASE NOTE: You have to reset your custom query <?php $args = array( ‘posts_per_page’ => 1, ‘post__in’ => get_option( ‘sticky_posts’ ), ‘ignore_sticky_posts’ => 1 ); $my_query = new WP_Query( $args ); $do_not_duplicate = array(); while … Read more

Why doesn’t is_page(id) work in functions.php?

is_page() relies on a complete global $wp_query object. If you call it before the action template_redirect has been fired, it might be impossible to get that data. Wait for a proper action. Example: add_filter( ‘template_include’, function( $template ) { if ( is_page( 27 ) ) echo ‘this is the apply page’; return $template; }); You … Read more