Tag Info

New answers tagged

1

Use 'offset' in your query to start two posts before the current one. So if you're iterating through posts and the current post is number 14, then offset by 12 and ask for 5 posts. This will give you numbers 12-16 which is what you need and nothing more. $args = array( 'category' => $mycat, 'numberposts' => 5, 'offset' => 12, ); $posts = ...


0

If you want to query for a large set of posts, but don't need full information for each you can use 'fields' => 'ids'm see Return Fields Parameter. In this case, I concur with comment, it might make more sense to simply retrieve adjacent post several times. You'll have to use setup_postdata() and wp_reset_postdata() since get_adjacent_post() doesn't ...


1

As I already stated in a comment to your answer, you should never make use of query_posts Note: This function isn't meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of a page by replacing it with new ...


0

Instead of a function to place on functions.php, I find a workaround that can be placed on a template file: <?php global $authordata, $post; query_posts( array( 'author' => $authordata->ID, 'post_type' => 'post', 'post__not_in' => array( $post->ID ), 'paged' => $paged, 'posts_per_page' => 5 )); if (have_posts()) : ...


0

In your code after global $authordata, $post; add $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; and change your code from $authors_posts = get_posts( array( 'author' => $authordata->ID, 'post_type' => 'kenniscentrum', 'post__not_in' => array( $post->ID ), 'posts_per_page' => 5 ) ); to $authors_posts = get_posts( ...


-1

Thank you for the Tax_Query advice. I have done the following and it works perfectly. $myquery['tax_query'] = array( array( 'taxonomy' => 'category', 'terms' => array('category-slug'), 'field' => 'slug', ), array( 'taxonomy' => 'post_tag', 'terms' => array('tag-slug'), 'field' ...


0

As suggested in a comment, the best approach here will be to make use of a tax_query. You have much more flexibility and the ability to run more complex queries specially when you are working with more than one taxonomy (in this case category and post_tag). You can try something like this $args = [ 'tax_query' => [ 'relation' => 'AND', ...


1

The function you are using, get_most_recent_post_of_user, won't work as it only retrieves the latest post from the author. It cannot retieve a list of posts Walks through each of a user's blogs to find the post with the most recent post_date_gmt. You will most probably be better of using either WP_Query or get_posts to achieve this. You should first ...



Top 50 recent answers are included