How can I use WP_Query to display selected Category posts from the custom post?

I am using custom post type plugin and I am trying to loop only selected post for a particular category within my custom post. I would like to loop only selected category. Any suggestion?

Here is my code :

<?php
$loop=new WP_Query(array(
    'post_type'=>'custom post';
    'taxonomy '->'private';
    'sort_column' => 'post_date',
    'posts_per_page'=> -1 ,
    'order' => 'ASC')
); 
if ( $loop->have_posts() ){?>

    <?php 
    while ( $loop->have_posts() ) 
    {
        $loop->the_post();
        $meta=get_post_meta(get_the_id(),'');

?>

Related posts

3 comments

  1. Use tax query of wordpress inside the wp_query

    $args = array(
        'post_type'=>'custom post';
        'posts_per_page'=> -1 ,
        'order' => 'ASC'
        'orderby' => 'ID'
    
        'tax_query' => array(
            array(
                'taxonomy' => 'private',
                'field'    => 'slug',
                'terms'    => 'bob',
            ),
        ),
    );
    $query = new WP_Query( $args );
    

    and replace the 'terms' => 'bob', with 'terms' => '<your category slug>', Slug can be checked from back-end

  2. According to the wp_query docs

    $loop=new WP_Query(array(
        'post_type' => 'custom post',
        'taxonomy' =>'private',
        'sort_column' => 'post_date',
        'posts_per_page'=> -1,
        'order' => 'ASC',
        'cat' => 19
    )
    ); 
    
  3. use it like this:

    <?php
    $loop=new WP_Query(array(
        'post_type'=>'custom post';
        'posts_per_page'=> -1 ,
        'order' => 'ASC',
        'orderby' => 'ID',
    
        'tax_query' => array(
            array(
                'taxonomy' => 'private',
                'field'    => 'slug',
                'terms'    => 'bob'
            ),
        ),
    );
    ); 
    if ( $loop->have_posts() ){?>
    
        <?php 
        while ( $loop->have_posts() ) 
        {
            $loop->the_post();
            $meta=get_post_meta(get_the_id(),'');
    
    ?>
    

Comments are closed.