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

Query posts by views on category page

Don’t nullify the main query, this breaks stuff. Also, avoid using the $wp_query global as a custom variable. This breaks the main query and causes issues. You can also try adding ‘suppress_filters’ => true, to your arguments to suppress any custom filters if you are using any custom filters. Also, don’t use TEMPLATEPATH, it is … Read more

Adding a block with query in homepage

In both your queries you are doing it wrong. You are running a separate instance of WP_Query for every argument set $args = array( ‘posts_per_page’ => $count, // Limit count ); $query = new WP_Query( ‘cat=1’ ); $query = new WP_Query( $args ); Should be $args = array( ‘posts_per_page’ => $count, ‘cat’ => 1 ); … 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

Custom navigation : show posts in sets of 4

I’m not sure if this is going to solve your whole issue, but you can add the paged parameter to your current custom query. I don’t know why you have set the offset parameter. If your offset is 0, omit it completely Also, remember to reset your post data after your custom query. Try something … 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

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

Display post from custom post type

You need to add ‘post_type’ => array(‘post’, ‘opinion’) to your $normal_args array and maybe remove the meta_query?. Are you sure you have any opinions with a _custom_blog_enhome of 1? Start from $normal_args = array( ‘post_type’ => ‘opinions’, ‘post_status’ => ‘publish’ ); and add arguments one by one and watch the results.