• I have searched the forum for the past few hours now and can’t seem to find what I am looking for, i am beginning to think this is not possible.

    I have a custom post type ‘project’ within this post type I have two taxonomies which each have 3 terms similar to below:

    ‘project’
    -> ‘houses’
    –> coastal
    –> country
    –> urban

    -> ‘gardens’
    –> coastal
    –> country
    –> urban

    When I click on a project I need to find the taxonomy and the term in order for my query to work on single.php query below:

    $args = array(
    'posts_per_page' => -1,
    'post_type' => 'projects',
    'tax_query' => array(
    	array(
    		'taxonomy' => $my_taxonomy,
    		'field' => 'slug',
    		'terms' => $my_term
    	)
    )
    );

    So in order for this query to work I need $my_taxonomy and $my_term, again not sure if it is possible i have found many topics where people have been looking to get the terms by using the taxonomy but I don’t have the taxonomy and want my single.php to be dynamic.

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • <?php
    $current_query = $wp_query->query_vars;
    $wp_query = new WP_Query();
    $wp_query->query(array(
    	$current_query['taxonomy'] => $current_query['term'],
    	'posts_per_page' => 10,
    ));
    
    while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    Thread Starter alanlightbox

    (@alanlightbox)

    Thanks for your reply I used an alternative method with advanced custom fields since I was unable to achieve what I wanted at the time, no doubt this will come in handy for my next project.

    Thanks very much

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get taxonomy of a post for single.php’ is closed to new replies.