Forums

Query Custom Taxonomy and Category (5 posts)

  1. themarcthomas
    Member
    Posted 6 months ago #

    Hey,

    I'm having a bit of trouble writing the correct query for this. I want to do the following

    1) Build an archive for each individual artist mentioned on my site. I have managed this (see: http://plastik.me/artist/summer-camp-2/)
    2) On that page I want to display all of the albums by that particular artist. Thus far, I have been tagging each album review post with a 'review' category.

    However, when it comes to doing the query that only displays 'albums' by the artist, I can't manage to write the code. My thinking is that something like this will do:

    $args = array(
    	'tax_query' => array(
    		'relation' => 'AND',
    		array(
    			'taxonomy' => 'artist',
    			'field' => 'slug',
    			'terms' => array( '[I need something that will echo the artist archive here]' )
    		),
    		array(
    			'taxonomy' => 'category',
    			'field' => 'id',
    			'terms' => array( 1424 ),
    		)
    	)
    );
    $query = new WP_Query( $args );

    Can anyone enlighten me on the following:

    1) Is this the correct query to use?

    2) How can I make the 'artist' dynamic so that I don't have to hard code it for each artist?

    Thanks,
    Marc

  2. keesiemeijer
    moderator
    Posted 6 months ago #

    maybe this on a archive page [untested]:

    'terms' => array( get_query_var('term') )
  3. themarcthomas
    Member
    Posted 6 months ago #

    Got it! The issue was that the variable $query was not the variable I used to display the posts. Stupid me!

    Changing it to $the_query made it right.

    @keesiemeijer - the fix you put there also needed to be made. Thank you kindly.

    Thank you.

  4. keesiemeijer
    moderator
    Posted 6 months ago #

    you're welcome. Glad you got it resolved.

  5. sjaved
    Member
    Posted 5 months ago #

    Hi Friends,

    I am new to wordpress plugin development. I want to create my plugin for directory listings which consists of categories and sub categories.

    I have created a plugin for bankers previously but I have no idea about custom taxonomies.

    Can u please give me any link for the tutorial that how to use my custom categories and posts.
    I shall be very thankfull to you.

Reply

You must log in to post.

About this Topic