skip to Main Content

I am a semi beginner wordpress php developer, and I try to combine 2 different category_name here.

$args = array(
    'post_type'     => 'project',
    'showposts'     => 2,
    'category_name' => $post->post_name,
    'category_name' => 'featured',
    'orderby'       => 'menu_order',
    'order'         => 'ASC',
);

I guess that I may need to combine the 2 category_name here. Do you know how to do it?

I want to know if it is possible to have 2 different types of filters under the same category_name.

2

Answers


  1. You can use get_cat_ID to get the ID of the category name.

    $args = array(
        'post_type'    => 'project',
        'showposts'    => 2,
        'category__in' => array( get_cat_ID( $post->post_name ), get_cat_ID( 'featured' ) ),
        'orderby'      => 'menu_order',
        'order'        => 'ASC',
    );
    
    Login or Signup to reply.
  2. Check this page for more information: http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters
    
    
    $args = array(
        'post_type'    => 'project',
        'posts_per_page'    => 2,
        'orderby'      => 'title',
        'order'        => 'ASC',
        'tax_query' => array(
            'relation' => 'AND',
            array(
                'relation' => 'OR',
                array(
                    'taxonomy' => 'category',
                    'field' => 'slug',
                    'terms' => 'category-1',
                ),
                array(
                    'taxonomy' => 'category',
                    'field' => 'slug',
                    'terms' => 'category-2',
                ),
                array(
                    'taxonomy' => 'category',
                    'field' => 'slug',
                    'terms' => 'category-3',
                ),
                array(
                    'taxonomy' => 'category',
                    'field' => 'slug',
                    'terms' => 'category-4',
                ),
            ),
            array(
                'taxonomy' => 'category',
                'field' => 'slug',
                'terms' => 'category-5',
            ),
        )
        
    );
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search