0

Is there a way to instantiate a WP_Query object—filtered by post_meta and taxonomy_meta—within the loop of which I can have access to both post and taxonomy-archive methods (like the_excerpt and get_cat_name)?

Want to return all "featured" posts and taxonomy archives to display details from.

This gets all the featured posts:

$args = array(
'post_type' => 'post_type', 
'post_status' => 'publish',
'meta_query'  => array(
            array(
                'key' => 'featured-meta-checkbox',
                'value' => 'yes'
            )
        ),
'fields' => 'id',
'posts_per_page' => -1
);
$query = new WP_Query($args);
// Some HTML
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
// display content
endif; endwhile;
// More HTML

Then I am looping through taxonomy terms

$taxonomies = get_object_taxonomies( (object) array( 'post_type' => 'post_type' ) );
$terms = get_terms( $taxonomy );
foreach( $terms as $term ) : 
    if (get_term_meta( $term->term_id, 'featured-meta-checkbox', true ) == 'yes'):
// Here we can use
    get_cat_name( $term->term_id );
    get_category_link( $term->term_id );
    category_description($term->term_id);

And I can probably even find a way to display the category_thumbnail that the parent theme provides (or use Taxonomy Images).

So I end up with a slider (in this case) displaying featured posts, each with an image, excerpt, title, followed by title, (trimmed) description and probably image for featured categories.

But this approach is inelegant, and also puts all of the Taxonomy Archives after the featured posts. Ideally I'd like to be able to intermingle the posts and archive, although I'm not sure based on what criteria yet.

UPDATE: For what it's worth, the following is what pulled in the category image provided by the Total theme:

<?php echo wp_get_attachment_url( WPEX_Term_Thumbnails::get_term_thumbnail_id($term->term_id) ); ?>;

Basically using a static method from Total's WPEX_Term_Thumbnails class.

  • You've described what you have and don't want, but I'm not sure what results you're trying to achieve. – Milo May 18 '17 at 0:36
  • Hmmm. Great point. Will update question. – MikeiLL May 18 '17 at 0:39
  • @Milo I hope the update clarifies things. – MikeiLL May 18 '17 at 0:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.