get_terms with count using meta value
-
I created a custom post type (jobs), with taxonomies (category, salary range etc) for a jobs board. Each post has a meta key of closing_date to specify the date the post is closing.
I am modifying the query for the jobs pages to only feature jobs that are published and before the closing data meta key value.
add_filter( 'pre_get_posts', 'jobs_query_for_beautiful_filters' ); function jobs_query_for_beautiful_filters( $query ) { $timecutoff = date("Ymd"); // Do nothing if not on Job page, we only want to effect this query not all! if ( (! is_post_type_archive('sc_jobs') ) && ( ! is_tax( 'job_categories' ) ) ) { return; } $query->set( 'post_type', 'sc_jobs' ); $query->set( 'orderby', 'meta_value' ); $query->set( 'meta_key', 'closing_date' ); $query->set( 'meta_compare', '>=' ); $query->set( 'meta_value', $timecutoff ); $query->set( 'order', 'ASC' ); }*I am using the plugin Beautiful Taxonomy filters to provide the search tools for the jobs post type.
On the archive and taxonomy pages, I show a list of the categories and ideally the number of jobs within that taxonomy
<ul> <?php $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>'; } ?> </ul>My problem is that the count is displaying all published jobs and ignoring the closing_date meta key.
Is it possible use the meta key?
Thanks
The topic ‘get_terms with count using meta value’ is closed to new replies.