Display a post from custom post type only if all the selected taxonomies and custom field value matches the record

You have set “roll_number” custom field in tax_query. It should be in “meta_query”. Please try the updated code: tion exam_result_filter_function(){ $args = array( ‘post_type’ => ‘exam_result’, ); if( isset( $_POST[‘school_class’] ) || !empty( $_POST[‘academic_year’]) || !empty( $_POST[‘roll_number’]) ){ $args[‘tax_query’] = array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘school_class’, ‘field’ => ‘id’, ‘terms’ => $_POST[‘school_class’], ), … Read more

Custom Post type slider with thumbnail navigation

Follow this flow: Define an empty array $nav_img = array(); outside the loop. Inside the loop while you fetch the featured image, push the URL to the array too like this $nav_img[]=’your_image_here’ ; Then inside <div class=”slider-nav-thumbnails”></div> you can simply do a for each loop to set the images as thumb. UPDATE: Here I added … Read more

Should I reset $wp_query?

The query is right and its working. But should I reset something? Yes! Should I reset them both or just one of them, or is it fine like above? Neither! Your WP_Query object is self contained in $query, so there’s no reason to touch the $wp_query global variable, why would you? $wp_query represents the main … Read more

Query not work for current taxonomy

It looks like your query is for ALL posts in that post type as you are overwriting $posts when using $posts = get_posts(). You need to pass the Taxonomy parameter correctly as explained here like this: $args = array( ‘post_type’ => ‘post’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘people’, ‘field’ => ‘slug’, ‘terms’ => ‘bob’, … Read more

Issue with custom loop in Archive page

The problem is you aren’t saving your custom query’s results. To do it your way, you would need to save the query’s results to a variable, like so: $myposts = query_posts( $archive_args ); if ( $myposts->have_posts() ) : while ($myposts->have_posts()) : $myposts->the_post(); However, that’s not the most efficient way. WP runs the default query in … Read more

get_users with array as meta_value

First, can use meta_query, but, you should change your values to use the proper date format, e.g. 2020/01/02 for January 2nd, rather than a regional format. See https://en.wikipedia.org/wiki/ISO_8601 for more details. Second, your LIKE query is going to be very expensive, and achieving what you want while still using a LIKE query will be even … Read more