0
votes

Ive been looking and am unable to find a working solution. Here is the example:

I created a custom post type called "ads". The objective is to be able to create posts under ads and have them show up in there desired template. Im able to do this but I created 3 Custom Categories and am not able to use that for filtering.

my code is:

<?php query_posts('post_type=ads&posts_per_page=4&tag=home-above&orderby=rand'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>



      <?php if ( function_exists('has_post_thumbnail') && has_post_thumbnail($post->ID) ) {
      $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), full ); ?>
        <img class="has-tip tip-top" data-width="210" title="<?php the_field('hover_text'); ?>" src="<?php echo $thumbnail[0]; ?>" />

      <?php }else{ ?> 
      <img src="/DetroitSounds/wp-content/uploads/2013/01/youradhere.jpg" />
      <?php } ?> 



<?php endwhile; ?>  

<?php endif; wp_reset_query();?>

The custom categories names are "Home Page Above" ( slug=home-page-above ), "Home Page Below" ( slug=home=page-below ) and Inner Pages ( slug=inner-pages )

In the above code I have a tag which is actually achieving the effect I want, but Im afraid the backend usability is not as straight forward for the client.

Im also a bit confused if I'm even using that taxonomy correctly?

Any ideas would be great. Thanks

2
Never use query_posts, it is unreliable, breaks the main query and fails in most situations on pagination. Rather use WP_QueryPieter Goosen

2 Answers

1
votes
$args = array( 'post_type' => 'ads',
               'posts_per_page'=>4,
               'tax_query' => array(
                      array(
                      'taxonomy' => 'type_taxonomy_name_here', //i don't know your taxonomy name
                      'field' => 'slug',
                      'terms' => 'home-page-above,home-page-below,inner-pages'
                      )
                )
            );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
  the_title();
  echo '<div class="entry-content">';
  the_content();
  echo '</div>';
endwhile;
0
votes

try using category_name=your-category-slug, rewriting your first line of code to be:

<?php query_posts('post_type=ads&posts_per_page=4&category_name=home-page-above&orderby=rand'); ?>