0

I need posts within a taxonomy category that are tagged “featured” to show up first

https://yoga.gcclients.com/listing-category/bucks-county/

Right now it’s pulling posts from ALL posts within the business listing taxonomy tagged “featured” instead of ones from the category of the page the user is looking at

so if in on bucks county page - it should pull posts that are tagged “featured” and are in the bucks county category only

Or if they view another category for instance - New Jersey - https://yoga.gcclients.com/listing-category/new-jersey/ it should pull posts tagged “featured” that are in the New Jersey category only

Here is the code we are currently using:

<!-- /* START FEATURED BUSINESSES */ -->


<ul class="archive-businesses">
<?php 
$args = array( 'post_type' => 'businesslistings', 'posts_per_page' => 6, 'orderby' => rand, 'tag' => 'featured' );
$the_query = new WP_Query( $args ); 
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>



 <li class="archive-bizlist">
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail( array(300,300) ); ?></a>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
 <div id="archive-bizlisting-address">
<?php if(get_post_meta($post->ID, 'biz_street_address', true)): ?>
    <i><?php echo get_post_meta($post->ID, 'biz_street_address', true); ?></i><br />
<?php endif; ?>

<?php if(get_post_meta($post->ID, 'biz_city', true)): ?>
     <i><?php echo get_post_meta($post->ID, 'biz_city', true); ?>,</i> 
<?php endif; ?>

<?php if(get_post_meta($post->ID, 'biz_state', true)): ?>
    <i><?php echo get_post_meta($post->ID, 'biz_state', true); ?></i>&nbsp;
<?php endif; ?>


<?php if(get_post_meta($post->ID, 'biz_zip_code', true)): ?>
    <i><?php echo get_post_meta($post->ID, 'biz_zip_code', true); ?></i>
<?php endif; ?>


</div>
       <?php the_excerpt(); ?>
</li> 


<?php endwhile;?>
</ul>
 <?php endif; ?>


<!-- /* END FEATURED BUSINESSES */ -->
0

I really hope somebody can give you a much simpler answer, but this is pretty much all I can think of at the moment.

If you're okay with all the listings being on a single page you could do something like this:

<?php
// Get the slug of the page to use in our category argument 
global $post;
$post_slug = $post->post_name;
?>

<?php
$args = array(
    'category_name' => $post_slug,
    'post_type' => 'businesslistings',
    'posts_per_page' => -1,
    'orderby' => rand,
    'tag' => 'featured'
);
$featured_query = new WP_Query( $args );
?>

<?php if ( $featured_query->have_posts() ) :  ?>
<?php while ( $featured_query->have_posts() ) : $featured_query->the_post(); ?>

    // Display featured stuff

<?php endwhile;?>
<?php endif; ?>

<?php
$args = array(
    'category_name' => $post_slug,
    'post_type' => 'businesslistings',
    'posts_per_page' => -1,
    'orderby' => rand,
    // x below should be replaced with the featured tag's ID (link for instructions will be below)
    'tag__not_in' => 'x' 
);
$standard_query = new WP_Query( $args );
?>

<?php if ( $standard_query->have_posts() ) :  ?>
<?php while ( $standard_query->have_posts() ) : $standard_query->the_post(); ?>

    // Display standard stuff stuff

<?php endwhile;?>
<?php endif; ?>

References:

Using WordPress tags in the WP_Query: WordPress Codex

Getting the page slug: Stack Exchange

Getting your tag's ID: Stack Exchange

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.