0
$args = array(
    //'post_type' => 'article',
    'posts_per_page' => 5,
    'category'     => 'starter',
    'meta_query' => array(
                array(
                'key' => 'recommended_article',
                'value' => '1',
                'compare' => '=='
                    )
                )
);
$query = new WP_Query($args);
while($query->have_posts()){
    the_content();
    } 
1

Your question is very unclear (given that you don't actually ask a question), but there are 2 problems with your code, both of which are corrected below:

    $args = array (
    //'post_type' => 'article',
    'posts_per_page' => 5,
    'category_name' => 'starter', // changed from 'category' to 'category_name'
    'meta_query' => array (
        array (
            'key' => 'recommended_article',
            'value' => '1',
            'compare' => '=', // changed from '==' to '='
            ),
        ),
    ) ;
$query = new WP_Query ($args) ;
while ($query->have_posts ()) {
    the_content () ;
    }

For the details of why these changes are necessary, see WP_Query, Category Parameters and WP_Query, Custom Field Parameters.

1
  • Hi I created a custom post like product .I want to display all categorises and their posts. Thanks Apr 7 '17 at 10:05
0

I have try this way and worked for me

$terms =  get_terms( array(
                        'taxonomy' => 'category',
                        'hide_empty' => true,
                        'orderby'=> 'name',
                        'order'=>'ASC'
                    ));

                    foreach( $terms as $term){
                        $termChildren = get_term_children($term->term_id, 'category');
                              $args = array('post_type' => 'mycustompost',
                                'post_status' => 'publish',
                                'posts_per_page' => '-1',
                                'orderby'   => 'ID',
                                'order' => 'ASC',
                                'tax_query' => array(
                                    array(
                                        'taxonomy' => 'category',
                                        'field' => 'slug',
                                        'terms' => $term->slug
                                    ),                                                  
                                )
                            );
                            $query = new WP_Query($args);
                            while ($query->have_posts()): $query->the_post();
                                  the_title(); the_content();
                            endwhile;
                     }

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.