[resolved] Loop- want to show posts in two categories using category_name (2 posts)

  1. MTWK-Applied
    Posted 3 years ago #

    The documentation indicates that I can get a post that is in two categories by the following. I would like to be able to do this using category_name not category. Is this possible?

    his shows posts that are in both categories 2 and 6:

    $query = new WP_Query( array( 'category__and' => array( 2, 6 ) ) );

  2. MTWK-Applied
    Posted 3 years ago #

    Got another resolution. Found a function that allows me to convert the get the category id if you have the category name.`function get_category_id($cat_name){
    $term = get_term_by('name', $cat_name, 'category');
    return $term->term_id;
    $category_ID = get_category_id('WordPress Tutorials');`

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.