WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. MTWK-Applied
    Member
    Posted 1 year 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
    Member
    Posted 1 year 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

Tags

No tags yet.