0

I am using a custom post-type, in post there are a checkbox meta field for featured post.

So there are two scenarios.

  1. First with featured posts
  2. Second with non featured

When I called featured posts with meta_query its result 100% perfect.

Here is my code:

$c_clients_args = array(
                    'post_type' => 'clients_testimonials',
                    'posts_per_page' => 6,
                    'order' => 'ASC',
                    'meta_query' => array(
                                        array(
                                            'key' => 'c_client_feature',
                                            'value' => 'on'
                                        )
                                    )
                );

$c_clients_result = new WP_Query($c_clients_args);

if($c_clients_result->have_posts()) :
    while($c_clients_result->have_posts()) :
         $c_clients_result->the_post();

         // My result
    endwhile;
endif;

But when I call non featured posts with meta_query the Page goes blank.

Here is my code:

$c_client_args = array(
                    'post_type' => 'clients_testimonials',
                    'posts_per_page' => 999,
                    'order' => 'ASC',
                    'meta_query' => array(
                                        array(
                                            'key' => 'c_client_feature',
                                            'value' => 'on',
                                            'compare' => 'NOT LIKE'
                                        )
                                    )
                );

I also tried != and NOT IN

So please guide me.

  • and if you use 10 instead of 999? why do you think it has anything to do with the query at all? – Mark Kaplun Apr 27 '16 at 7:16
  • I want infinite data of non featured post – deemi-D-nadeem Apr 27 '16 at 7:17
  • and nothing happen when i convert 999 to 10 – deemi-D-nadeem Apr 27 '16 at 7:19
  • There is not "infinite" data in WordPress, but if you want to get all posts that match the query, use nopaging => true and posts_per_page => -1. – cybmeta Apr 27 '16 at 7:44
  • I don't see anything wrong in your code. Are you sure that c_client_feature meta field exists for non featured posts? – cybmeta Apr 27 '16 at 7:46
0

try this second query

  $c_client_args = array(
                    'post_type' => 'clients_testimonials',
                    'posts_per_page' => 999,
                    'order' => 'ASC',
                    'meta_query'  => array(
                         'relation' => 'OR',
                          array(
                             'key' => 'c_client_feature',
                             'compare' => 'NOT EXISTS' 
                          ),
                          array(
                             'key' => 'c_client_feature',
                             'value' => 'on',
                             'compare' => 'NOT IN' 
                          ),
                        )
                );
  • noting happend bro :( – deemi-D-nadeem Apr 27 '16 at 11:34
  • use wp_reset_query(); after end of loop – user5200704 Apr 27 '16 at 11:36
  • comment all code your first query which is working and check second is working ? means remove first query for testing purpose – user5200704 Apr 27 '16 at 11:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.