0

how to display books of selected category in the sidebar in WordPress without any plugin.

I want to display books in sidebar(Web Page) whose category is activated from the widget(Admin) through checkbox or something like that.

Pedo
  • 194
  • 1
  • 2
  • 14

1 Answers1

0
$query = new WP_Query( array(
    'post_type' => 'book',          // name of post type.
    'tax_query' => array(
        array(
            'taxonomy' => 'Book1',   // taxonomy name
            'field' => 'term_id',           // term_id, slug or name
            'terms' => 1,                  // term id, term slug or term name
        )
    )
) );

while ( $query->have_posts() ) : $query->the_post();
    // do stuff here....
endwhile;

/**
 * reset the orignal query
 * we should use this to reset wp_query
 */
wp_reset_query();
naval
  • 49
  • 5
  • not working and also I m not able to know what to do – Pedo Dec 24 '19 at 17:17
  • Provide me detail instructions with screenshot or site url so i can help you – naval Dec 26 '19 at 09:29
  • go to this link i have uploaded same question in detail https://stackoverflow.com/questions/59488755/how-to-retrieve-postsbooks-based-on-categorytaxonomy-in-wordpress – Pedo Dec 26 '19 at 12:54