2 queries with counters

On the advise of Robert and Pieter I rewrote the loops using WP_Query instead of query_posts. It works now. Thanks guys. Here’s the code: <ul class=”tabs”> <li class=”tab-link current” data-tab=”tab-1″>Most Popular</li> <li class=”tab-link” data-tab=”tab-2″>Recent</li> </ul> <div id=”tab-1″ class=”tab-content current”> <div class=”slider”> <div class=”slide”> <?php $count = 0; $query = new WP_Query( array( ‘meta_key’ => ‘post_views_count’, … Read more

Display all attached image of every post of custom post type and link to original post

You have two issues here. The use of $image->ID in this line wp_get_attachment_image($image->ID, ‘video-thumb’); This will give you the following error: NOTICE Error: [8] Undefined variable: image In all honesty, I think that should actually be $post->ID get_permalink() returns the permalink to the current post, which in this case is the image. If you want … Read more

Function using get_posts() with tax_query not working when called from functions.php

For testing purposes in your functions.php file, try this – add_action(‘init’, ‘my_test_get_all_bands’, 99); function my_test_get_all_bands(){ echo ‘<pre>’; print_r(get_all_bands()); echo ‘<pre>’; } As I was attempting to say in my comment to your question (and as Pieter Goosen explained rather better), if your taxonomies have not yet been registered then the tax_query portion of your get_all_bands() … Read more

List all Custom Post Type posts excluding certain Taxnomy term

Sounds like you’re looking for the NOT IN value of the operator argument of a tax_query. Depending on your situation, you should use either WP_Query or pre_get_posts. Your tax_query would then look something like this: ‘tax_query’ => array( array( ‘taxonomy’ => ‘{your taxonomy slug}’, ‘field’ => ‘slug’, ‘terms’ => ‘featured’, ‘operator’ => ‘NOT IN’ ) … Read more

query_posts clarification needed

Can someone please explain how “$posts” is used within the loop? It isn’t. It returns the array of queried posts , but it is insignificant and not used at all: if you remove it than the code works the same: global $query_string; query_posts($query_string.’&cat=-9′); if (have_posts()) : while (have_posts()) : the_post(); … endwhile; endif; This is … Read more

How to extract information from a wp_query result?

The below is starting after you do your query: $slide_list = array(); if ( $slides->have_posts() ) { while ( $slides->have_posts() ) { Grab the next slide using next_post to grab it without stomping globals $slide = $slides->next_post(); $slide_id = $slide->ID; Your image title is your post title: $slide_title = $slide->post_title; Your href is your permalink … Read more

Use post in multiple places on a page with multiple posts

You can make use of the the_content filters to apply markup to get_the_content() $content = get_the_content(); echo apply_filters( ‘the_content’, $content ); You’ll need to do the same for get_the_title() where you would use the_title filters instead of the_content Just another note on your code, remember to reset each of your custom loops with wp_reset_postdata(); just … Read more

More efficient way to list posts by category [duplicate]

My suggestion would be to pass different arguments to Wp_Query Class. using ‘cat’ property, passing category Ids. <?php $custom_query = new WP_Query( array( ‘cat’ => ‘1,2,3,4’ ‘post_type’ => ‘my_post_type’, ‘posts_per_page’ => -1, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’ ) ); ?> OR using ‘category_name’ property passing category slug’s as string parameters. <?php $custom_query = new … Read more