meta query with get_terms
-
Hi
I have a custom post type for a jobs facility on the website. The closing date is meta data and should pull the job (post) from the website once that date has passed.
Not a problem so far, my query does this well to display live jobs;
$timecutoff = date("Ymd"); $args = array( 'post_type' => 'sc_jobs', 'orderby' => 'meta_value', 'meta_key' => 'closing_date', 'meta_compare' => '>=', 'meta_value' => $timecutoff, 'order' => 'ASC', 'paged' => $current_page, 'posts_per_page' => 5 ); $my_query = new WP_Query($args);For job categories, I set up the taxonomy ‘job_categories’.
I want to list out the categories that feature live jobs, and display a post count next to the category
$terms = get_terms('job_categories'); if ( !empty( $terms ) && !is_wp_error( $terms ) ){ echo '<ul>'; foreach ( $terms as $term ) { $term = sanitize_term( $term, 'job_categories' ); $term_link = get_term_link( $term, 'job_categories' ); echo '<li><a href="' . esc_url( $term_link ) . '">' . $term->name . ' (' . $term->count . ')' . '</a></li>'; } echo '</ul>'; }This however doesn’t take in to account my closing date meta, so the post count is incorrect.
I’m stuck on this part, I thought this may be good but it results in nothing displayed
$timecutoff = date("Ymd"); $args = array( 'taxonomy' => 'job_categories', 'orderby' => 'meta_value', 'meta_key' => 'closing_date', 'meta_compare' => '>=', 'meta_value' => $timecutoff ); $terms = get_terms($args);Can anyone help me query get_terms to include closing date?
Thanks
The topic ‘meta query with get_terms’ is closed to new replies.