Display custom post type by custom taxonomy

The problem is in your tax_query terms parameter. Try: ‘tax_query’ => array( array( ‘taxonomy’ => ‘listings_tags’, ‘field’ => ‘slug’, ‘terms’ => $custom_term->slug, ), ), And if you want posts from just basic, there’s no need for getting terms and loopin through. All you can do is WP_Query with tax_query terms parameter as ‘basic’.

Always using the same ARRAY on different querys

I don’t like using categories for this, as they are supposed to be semantic terms. I do, however, like the idea of the global array. Instead of creating a new query directly, I will filter it through a function that will add the results to a global array and return the results: I add this … Read more

How to Query Post

Try this: <ul> <?php global $post; $args = array( ‘numberposts’ => 5, ‘category’ => 1 ); $myposts = get_posts( $args ); foreach( $myposts as $post ) : setup_postdata($post); ?> <li><a href=”https://wordpress.stackexchange.com/questions/12234/<?php the_permalink(); ?>”><?php the_title(); ?></a> – <?php the_date(); ?></li> <?php endforeach; ?> </ul> More info: query_posts()

Query posts to get all but the most recent post

I had to use the WP_Query class: $the_query = new WP_Query(array( ‘category_name’ => ‘Recipe of the Week’, ‘offset’ => 1 ) And then reference my new query object in the template like this: <?php while ( $the_query-> have_posts() ) : $the_query->the_post(); ?>

Filter Loop by Custom Field Value

How about this: $my_query = new WP_Query(array( ‘post_type’=> ‘custom_type’, ‘post_status’ => ‘publish’, ‘meta_key’ => ‘my_custom_field’, ‘meta_value’ => ‘custom field value’ )); if($my_query->have_posts()): while($my_query->have_posts()):$my_query->the_post(); //All the post stuff here. endwhile; endif; wp_reset_postdata(); Check this out.

why to use query_posts() in custom page?

See When should you use WP_Query vs query_posts() vs get_posts()? For a custom post type or a simple page you don’t need query_posts(). Usually, you almost never need it, because it will replace the default query which leads to some counter-intuitive side effects. When in doubt use get_posts().

query_posts() – problem with “s” parameter

You shouldn’t use $_GET[‘s’] directly like that, and you definitely shouldn’t use query_posts, although I understand using it for testing. If you’re going to build your own search mechanism in this way, then you should run $_GET[‘s’]through the urldecode() function first, to make sure it doesn’t contain weird data that you might not expect and … Read more