WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#34833 closed defect (bug) (invalid)

When given 'tag' as an argument into wp_query it ignores suppress_filters

Reported by: BenzinNZ Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.3.1
Component: Query Keywords:
Focuses: Cc:

Description

I have the s2Member plugin installed and it is filtering out all posts on a page. I do not believe it to be a plugin issue as the behaviour occurs after the plugin filtering.

I have my own custom plugin that is getting a list of groups and bypassing the s2Member plugin by adding the 'suppress_filters' to true.

This works until I add the 'tag' argument to the argument array that is passed to the wp_query.

With no arguments:

<?php
$args = array();

Logged in : Can see the list of all posts.
Logged out : Cannot the list of posts

With the following arguments

<?php
 $args = array(        
        'suppress_filters' => false,
                'tag' => 'tagExample'
        );

Logged in: Can see all posts in the list that match the tag 'tagExample'
Logged out : Cannot see anything

<?php
 $args = array(        
        'suppress_filters' => true              
        );

Logged in: Can see all posts in the list
Logged out : Can see all posts in the list


<?php
         $args = array(        
        'suppress_filters' => true
                'tag' => 'tagExample'
        );

Logged in: Can see all posts in the list that match the tag 'tagExample'
Logged out : Cannot see anything

The wp_query is constructed like so.

<?php
$postsToList= new wp_query( $args );

This is weird behaviour that I can't seem to isolate to the plugin, so I believe it might be an issue with how the wp_query constructs the query.

The expected output is that the 'tag' argument will filter on the unfiltered list due to 'suppress_filters' rather than returning nothing. (there are definitely tags with the specified tag in the database as per the previous examples that work when logged in where the filters are not applied)

Let me know if I can provide any more information, or if there is any way I can help at all diagnosing this issue!

Cheers,

Change History (5)

#1 @BenzinNZ
6 years ago

Apologies just noticed I messed up the syntax when writing the original ticket. There should be a comma after the true.

<?php
         $args = array(        
        'suppress_filters' => true,
                'tag' => 'tagExample'
        );

#2 @swissspidy
6 years ago

  • Keywords reporter-feedback added

As mentioned on Slack:

Try to replicate the issue without s2member. I.e. run those examples and demonstrate that suppress_filters has changed value. A quick grep of WordPress tells me that WP never explicitly sets that value to false, so I strongly suspect the issue is with s2member or another plug-in/theme.

#3 @BenzinNZ
6 years ago

Thanks for the reply - at query.php#L3185 it looks like it will return false unless it's explicitly set to true. What I'll attempt to do wrangle up a clean installation and use a plugin that does a basic filter (probably something as simple as is_user_logged_in() and see if the same issues occur)

This should hopefully isolate the issue to core (if it isn't an issue with an installed plugin)

#4 @BenzinNZ
6 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Hmmm looks like something else is occurring outside of my scope of knowledge - some plugin must be editing the query. Going to be a long day :(

<?php
function pre_condition ( $where ) { return $where . ' AND 1=2 '; }
add_filter( 'posts_where' , 'pre_condition' );

 $args = array( 
        'suppress_filters' => true,
        'tag' => 'tagthatexists', 
);
$postsToList= new wp_query( $args );
var_dump($postsToList);   
?>

Works as expected on clean install!

#5 @swissspidy
6 years ago

  • Keywords reporter-feedback removed
  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.