Fetch only categorized posts

category__not_in is a private query var. This means you can only use it when constructing a query in PHP, not in a url. You would have to construct your own custom public query var and bind that to a filter that reads the category and then changes the query accordingly.

Create custom order sortby based on array of id

It looks like you want to order by post__in: $samp = array ( ‘post_type’ => ‘product’, ‘posts_per_page’ => 12, ‘post__in’ => $init_ids_arr, ‘orderby’ => ‘post__in’, // <– Try this to fix the order ); We might also want to skip the sticky posts with: ‘ignore_sticky_posts’ => true, If we want to display all of the … Read more

Querying, storing, and using data from 2 separate custom post types

For custom field queries you can’t use an array for multiple keys, unfortunately. What you want is something like this: $args = array( ‘post_type’ => array(‘gym_location’, ‘gym_term’), ‘orderby’ => ‘title’, ‘order’ => ‘DESC’, ‘meta_query’ => array( array( ‘key’ => ‘term_active’, ‘value’ => ‘1’, ‘compare’ => ‘==’ ), array( ‘key’ => ‘location_active’, ‘value’ => ‘1’, ‘compare’ … Read more

For each 3 posts, show a different post type

There are several ways to do this. Here’s an easy one. Let’s say you want to mix 9 ‘daily’ posts and 3 ‘quotes’. First you would have to get those posts: $dailies = get_posts(array(‘posts_per_page’ => 9, ‘post_type’ => ‘daily’)) $quotes = get_posts(array(‘posts_per_page’ => 3, ‘post_type’ => ‘quote’)) Next you would loop through them like this: … Read more

wp_query return nothing

You need to reference to your query, when starting the loop, otherwise it will show the posts found with the main query, instead of your custom query. Try: <?php $args = array( ‘post_type’=>’book’); $loop = new WP_Query( $args ); // Start the loop for your custom query if($loop->have_posts() ) : while ($loop->have_posts() ) : $loop->the_post(); … Read more

direct query to post_meta table

If I understand correctly you wish to retrieve your meta data from the database? Try looking at this WP function: https://developer.wordpress.org/reference/functions/get_metadata/ This will allow you to get the meta data you require dependent on the type of data you want to get, such as post meta data or page meta data etc. An additional read … Read more