Compare post-IDs within WP_Query? (Less than / Greater than)

I ended up using something like this: function filter_where( $where=”” ) { global $post, $prev_next; $the_ID = $post->ID; $where .= ” AND wp_posts.ID “; $where .= $prev_next==’next’ ? “< $the_ID” : “> $the_ID”; return $where; } add_filter( ‘posts_where’, ‘filter_where’ ); $nextProjQuery = new WP_Query( $filtered_query_args ); remove_filter( ‘posts_where’, ‘filter_where’ );

recent posts for different categories

If the blog / portfolio items are grouped into categories, you can do this at the top of your template file: <?php $portfolio_query = new WP_Query(‘posts_per_page=3&category_name=portfolio’); // note ‘portfolio’ is the category slug $blog_query = new WP_Query(‘posts_per_page=3&category_name=blog’); // note ‘blog’ is the category slug ?> Then in your markup: <?php if ($portfolio_query->have_posts()) : ?> <div … Read more

Sort query by author: 1 author, then others

You could do that with a custom posts_orderby: add_filter( ‘posts_orderby’, ‘wpa58715_posts_orderby’ ); function wpa58715_posts_orderby( $orderby_statement ) { if ( is_post_type_archive( ‘article’ ) ) { global $wpdb; $orderby_statement = “FIELD($wpdb->posts.post_author, 42) DESC, $wpdb->posts.post_author”; return $orderby_statement; } } Swap in your author ID for 42.

forming WP_Query for posts of all post types but from specific categories

According to the codex category_name only takes one string value. category_in accepts an array of category IDs: <?php $args = array( ‘category__in’ = array(1,4,6,8), // use IDs ‘post_type’=> array( $ptype, ‘post’, ‘test-btum’, ‘test-other’ ) ); $wp_query = new WP_Query($args); ?> It might be possible that the default category taxonomy is not registered to your custom … Read more

Having a Function Inside of the Loop

Before continuing, please read this: http://www.slideshare.net/andrewnacin/you-dont-know-query-wordcamp-netherlands-2012 It’s by a core WordPress developer and you should consider it required reading. You should never use query_posts, and it’s important to understand how to use loops correctly. That presentation will demonstrate the best practices, how, and why to use them. I can see the approach you’ve taken, what … Read more

Converting the_content string to an array?

Filter ‘img_caption_shortcode’. You get three arguments: an empty string, the attributes (including the attachment id), and the caption content. If you return anything but an empty string WordPress will print your return value instead of its own code. See wp-includes/media.php for details. Another option: hijack the caption handlers and create your own output or change … Read more

Advanced Taxonomy Queries WordPress

This is not a complete answer, but I hope this can help. It sounds like what you’re looking for is a “Faceted” navigation (or search or browsing) plugin. There are some plugins that do this already, like this one (from the FCC!). It’s possible that none of the existing plugins will match your needs, but … Read more