Extra filtering on post query

Rather than trying to manage access at the various places people might be able to see the posts, it’s probably safest to create custom user roles. For example, WP autogenerates RSS feeds, so if you’re only covering the single-post and archive views, you may not be covering the feeds themselves. If you create custom roles, … Read more

Filter on one post type with taxonimy and get other post type

tax_query with an ‘OR’ relation. This means that the query will fetch posts that meet either condition: they are ‘landing-pages’ with the specified taxonomy terms, or they are any of the other specified post types without additional taxonomy constraints. $args = array( ‘posts_per_page’ => 6, ‘post_status’ => ‘publish’, ‘order’ => ‘DESC’, ‘post_type’ => array(‘news’, ‘videos’, … Read more

Custom WP Query with neither ASC or DESC

Don’t think the effort worth it to do it with generating appropriate mysql statements as you can just use three queries, or sort the posts after you have the results of the query with both ways resulting in a mostly readable code. Main reason not to choose the above is if performance is critical. Another … Read more

Exclude page ID AND current page from wp_query of a Parent page

You can use get_the_ID() to retrieve the current page’s ID. $current_page_id = get_the_ID(); $args = array( ‘post_type’ => ‘page’, ‘posts_per_page’ => -1, ‘post_parent’ => ‘2’, ‘post__not_in’ => array( 4, $current_page_id ), ‘order’ => ‘ASC’, ‘orderby’ => ‘menu_order’ ); This kind of ID exclusion may cause query performance issues, especially when you have a great number … Read more