Custom post-type custom query – show all posts

This code: $term = get_term_by( ‘slug’, get_query_var($wp_query->query_vars[‘taxonomy’]), $wp_query->query_vars[‘taxonomy’]); … just fetches the term data for the currently queried term, it’s not altering the query in any way. To alter the query for your taxonomy term archives, you want to use the pre_get_posts action. Altering the query in the template just creates a new query, overwriting … Read more

WP_Query Class custom field parameters

As I understand it, IN, NOT IN, or BETWEEN work essentially like the MySQL operators of the same name. They are just abstracted somewhat. However, it sounds to me like you don’t need to worry about that. Your description makes me think that you are only worried about the meta_key itself and not any particular … Read more

Query Custom Post Type by Taxonomy

Use get_terms() with child_of (accepts numerical ID of parent term) argument to retrieve child terms and then loop through them and on each iteration use current term in the loop. Code example (not tested): $child_terms = get_terms( array( ‘child_of’ => $cameras_term_id ) ); foreach( $child_terms as $term ) { $args = array( ‘post_type’=> ‘rental_gear’, ‘type’ … Read more

multiple queries to get posts from same category?

Just add a counter to the loop. Just use $wp_query->current_post while ( have_posts() ) : the_post(); if($wp_query->current_post <= 1) // 1 because counter starts at 0 // <div>first 2 posts go here</div> if($wp_query->current_post > 1 <= 3) // <div>second 2 posts go here</div> if($wp_query->current_post > 3 <= 5) // <div>last 2 posts go here</div> endwhile;

Links in the_content not linked

Running make_clickable on the_content will get you your links. So… apply_filters(‘the_content’,’make_clickable’); … in your functions.php should link your content. It will be simple but you should get hyperlinks. I don’t see a way to add the target=”_blank” part. make_clickable is in wp-includes/formatting.php. You could use it as a pattern for a function that would add … Read more

Add content depending on page loaded

Assuming that you want to output content conditionally, depending on whether you are on a given set of static pages, by Page ID, you can simply wrap your code in an is_page() conditional. To determine if the current user is logged in, you can use the is_user_logged_in() conditional. For example // Array of Page IDs … Read more