• I have a few custom post types in my theme. One is nutrition, one is exercises.

    The website is set up with a membership plugin with different membership levels.

    I intend on creating categories for the difference membership levels such as:

    Post Type: Exercises
    Category: Level 1
    Category: Level 2
    Category: Level 3
    Category: Level 4
    Category: Level 5

    And I intend on having tags such as:
    Legs
    Arms
    10 Minutes
    30 Minutes
    Abs

    I am able to display all posts within a category but would like to have a button in widget bar for all of the tags however because I have different membership levels I would like to be able to have a button that links to the tag within a particular category.

    For example, I would like the button to be for the Legs tag but I would only want it to display the posts with the Legs tag in category “Level 1”

    Any help on this would be amazing.

    I found this post but don’t really understand it: https://wordpress.org/support/topic/display-blog-posts-from-specific-category-and-tag

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi Ajay,

    You’re probably looking for a multiple Taxonomy handling.

    Try this one:

    $args = array(
    	'post_type' => 'exercises',
    	'tax_query' => array(
    		array(
    			'taxonomy' => 'category',
    			'field'    => 'slug',
    			'terms'    => array( 'Level 1' ),
    		),
    		array(
    			'taxonomy' => 'tags',
    			'field'    => 'slug',
    			'terms'    => array( 'legs' ),
    		),
    		'relation' => 'AND',
    	),
    );
    $query = new WP_Query( $args );

    Please modify it to your needs.

    For more about this, you can try to read this post:
    http://www.codeinwp.com/blog/getting-posts-wp_query-class/

    See the Taxonomy Queries section.
    Or just read the post as a whole for getting better understanding of WP_Query. 😉

    Thread Starter Ajay

    (@ajaypatel)

    Thanks Erricgunawan,

    I think I have another way around the problem but thanks for sending that answer.

    No problem Ajay.

    The more important matter is you get your problem resolved 🙂
    And glad you can make it.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Display post with category and tag’ is closed to new replies.