I'm having a problem getting my query function. I need to run the loop, excluding a particular category.
I'm trying to use category__not_in
, but is not working at all some.
<?php
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'category__not_in' => array( '44' ),
'posts_per_page' => 9,
'paged' => get_query_var('paged')
);
$query = new WP_Query( $args );
query_posts($query);
?>
I've already tried:
'category__not_in' => array( '44' ),
'category__not_in' => array( 44 ),
'category__not_in' => '44',
'category__not_in' => 44,
But nothing works =(
Querying by Post Type You can query posts of a specific type by passing the post_type key in the arguments array of the WP_Query class constructor.
WP_Query is a PHP class for constructing queries to the WordPress database and returning posts, pages, or other custom objects to render on the page. It allows developers to build complex searches while removing the need to write separate SQL queries.
query_posts() is a way to alter the main query that WordPress uses to display posts. It does this by putting the main query to one side, and replacing it with a new query. To clean up after a call to query_posts, make a call to wp_reset_query() , and the original main query will be restored.
Try using tax_query instead :
<?php
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 9,
'paged' => get_query_var('paged'),
'tax_query' => array(
array(
'taxonomy' => '<YOUR TAXONOMY NAME>',
'field' => 'term_id',
'terms' => array( 44 ),
'operator' => 'NOT IN',
),
),
);
$query = new WP_Query( $args );
query_posts($query);
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With