On the page with id 239 I am trying to hide a certain post-format from displaying on it, however I am getting this error on all pages:
"Trying to get property of non-object in C:\wamp\www\wordpress\wp-includes\query.php on line 4337"
This is the code I am using in the functions.php file:
function exclude_campaigns( $query ) {
if( $query->is_main_query() && $query is_page(239) ) {
$tax_query = array( array(
'taxonomy' => 'post_format',
'field' => 'slug',
'terms' => array( 'post-format-link' ),
'operator' => 'NOT IN',
) );
$query->set( 'tax_query', $tax_query );
}
}
add_action( 'pre_get_posts', 'exclude_campaigns' );