• I have a post type called “lab” which has a taxonomy called “states”.

    I added this plugin and created a new post called “careers” and added a CPT “lab” as its taxonomy.

    So this is the order

    States
    – Labs
    –Careers

    When I click on a state I get its slug and list all “Lab” now I need to get all Careers that I added to a lab

    How can I get it? I tried the code below:

    $args = array(
    	'post_type' => "careers",
    	'tax_query' => array(
    'taxonomy' => 'lab',
    	'field' => 'slug',
    	'terms' => 'global-pathology',
    									'include_children' => false
    	),
    
    	'posts_per_page' => -1,
          'orderby' => 'date',
    	 'order' => 'DESC');
    	$posts = get_posts($args);

    But it’s not filtering by lab taxonomy

    • This topic was modified 5 years, 7 months ago by Cezar Ayran.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Cezar Ayran

    (@ayrancd)

    I didn’t find a solution using WP functions so I had to use a regular select using the code below:

    URL = state/florida/georgia….

    <?php
    	$tax = get_categories(array('taxonomy' => 'category_lab', 'posts_per_page' => 1,  'hide_empty' => false, 'slug' => $_GET["url"], 'orderby' => 'name', 'order'   => 'ASC'));
    	if(count($tax) == 0){
    		$stateN = "Try again";
    	}
    	foreach($tax as $cat) {
    		$stateN = $cat->name;
    	}
    ?>
    <div class="col12 title">
    	<?=$stateN?>
    </div>
    <div class="col12">
    	<?
    	$argsP = array(
        'post_type' => 'lab',
        'tax_query' => array(
            array(
              'taxonomy' => 'category_lab',
              'field' => 'slug',
              'terms' => $_GET["url"], 
              'include_children' => false
            )
          ), 'hide_empty' => false, 'orderby' => 'post_title', 'order'   => 'ASC'
    	);
    	$postsPages = get_posts($argsP);
    	if(count($postsPages) == 0){
    		echo "No results found :(";
    	}
    	foreach($postsPages as $post): ?>
    	<b><?=$post->post_title; ?></b><br>
    	<?
    		$results = $wpdb->get_results("SELECT wp_posts.ID, wp_posts.post_title FROM <code>wp_postmeta</code> inner join wp_posts on wp_postmeta.post_id = wp_posts.ID where wp_postmeta.meta_key = '_custom_post_type_onomies_relationship' and wp_postmeta.meta_value = ".$post->ID." and wp_posts.post_type = 'careers' and wp_posts.post_status = 'publish' order by wp_posts.post_title ");
    		if(count($results) == 0){
    			echo "No results found";
    		}
    		foreach($results as $career){ ?>
    	<a href="<?php the_field("pdf", $career->ID)?>" class="linkCareer"><?=$career->post_title?></a>
    	<? } ?>
    	<br><br>
    	<? endforeach; ?>
    </div>
    

    Is the close brace on line 8 valid?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Getting details’ is closed to new replies.