• Hello,

    I have a WordPress site with a custom post type “formation“, a custom taxonomy “domain” (specifically used for my custom post type), and a custom field “formation_type” used on my “formation” posts.

    What I’m trying to do is to customize the display of my template page taxonomy-domain.php, so that when I visit “mysite.com/domain/social“, I can sort the “formation” posts filed under the “social” taxonomy term, based on the value of a specific custom field : “formation_type”.

    I’ll show first the posts that have the value “certification”, then the posts that have the value “diploma”, etc.

    So far I have tried numerous solution, but can’t seem to find how to do that.
    How would you do that?
    Do I need to use multiple loops?

Viewing 1 replies (of 1 total)
  • Thread Starter Alex Martin

    (@apalmarlak)

    I came up with a working code that’ll show me only the post linked to a specific term and with a specific custom field value (“certification” on this example) :

    if ( have_posts() ) :
    
    	global $wp_query;
    	query_posts(
    		array_merge(
    			$wp_query->query,
    			array(
    			'meta_key'	=> 'formation_type',
    			'meta_value'	=> 'certification',
    			)
    		)
    	);
    
    	// Start the Loop.
    	while ( have_posts() ) : the_post();
    
    		get_template_part( 'content-domain' );
    
    	endwhile;
    	// Previous/next page navigation.
    	twentyfourteen_paging_nav();
    
    else :
    	// If no content, include the "No posts found" template.
    	get_template_part( 'content', 'none' );
    
    endif;

    However I need to perform the same query on the same page with my other custom fields value.

    My aim is to display a subtilte “Certifications“, followed by all the posts that have the “certification” custom field value.
    Then a subtitle called “Diploma“, followed by all the posts that have “diploma” custom field value.
    And so on.

    Any idea?

Viewing 1 replies (of 1 total)
  • The topic ‘taxonomy-custom.php : show only custom posts with a specific custom field value’ is closed to new replies.