Support » Fixing WordPress » Loop- want to show posts in two categories using category_name

  • Resolved MTWK-Applied

    (@mtwk-applied)


    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 ) ) );

Viewing 1 replies (of 1 total)
  • MTWK-Applied

    (@mtwk-applied)

    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’);`

Viewing 1 replies (of 1 total)
  • The topic ‘Loop- want to show posts in two categories using category_name’ is closed to new replies.