Skip Navigation

[Resolved] WP_Query calls failing on archive pages

This thread is resolved. Here is a description of the problem and solution.

Problem:
Custom post archives are not showing results to logged-in users though guest users do see the results.

Solution:
This was a bug introduced in Access 2.7 which has now been fixed. Updating to the latest version will resolve the issue.

This support ticket is created 5 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Tagged: 

This topic contains 9 replies, has 2 voices.

Last updated by Richard Marks 5 years, 6 months ago.

Assisted by: Nigel.

Author
Posts
#1242946

I am trying to:

I have a site that has been running for a year that uses custom content types with archive pages. These archive pages uses data generated by WP_Query to show custom content. Recently these pages have all stopped working.

I have found that copying the code to a non-template page works OK.

For example, there is a page hidden link which shows the content type 'venue' and which is generated using the template archive-venue.php - the template contains the code


$args = array(
	'post_type'              => array( 'venue' ),
	'order'                  => 'ASC',
	'posts_per_page'=>-1 ,
	'orderby'                => 'title',
);
global $post;
$query = new WP_Query( $args );


//echo "<pre>"; var_dump($query);

// The Loop
if ( $query->have_posts() ) {

When generated in this way the WP_Query returns

........
 ["request"]=>
  string(412) "SELECT   wp_posts.* FROM wp_posts  WHERE 1=1  AND wp_posts.post_type = 'venue' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') AND wp_posts.post_type <> 'venue' AND wp_posts.post_type <> 'meeting' AND wp_posts.post_type <> 'hospital' AND wp_posts.post_type <> 'news' AND wp_posts.post_type <> 'school-information' AND wp_posts.post_type <> 'carousel'  ORDER BY wp_posts.post_title ASC "
  ["posts"]=>
  array(0) {
  }

.....

(Note that the WHERE clause contains both wp_posts.post_type = 'venue' and wp_posts.post_type <> 'venue')

On the other hand if I copy the same code to a temporary non-template page it returns

["request"]=>
  string(188) "SELECT   wp_posts.* FROM wp_posts  WHERE 1=1  AND wp_posts.post_type = 'venue' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private')  ORDER BY wp_posts.post_title ASC "
  ["posts"]=>
  array(27) {
    [0]=>
    object(WP_Post)#14701 (24) {
      ["ID"]=>
      int(4979)
      ["post_author"]=>
      string(3) "124"
      ["post_date"]=>
      string(19) "2019-05-01 11:08:44"
      ["post_date_gmt"]=>
      string(19) "2019-05-01 10:08:44"

I don't know whether this is a WP bug or a Toolset bug. However I've noticed that some of the Views on template pages have stopped working too.

#1243045

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Richard

I notice that this issue happens when a user is logged-in, not when a guest visits the archive, and it appears related to Access, but I need to do some testing to confirm.

I won't do anything on your live site, I'm taking a copy to test with.

I'll update again when I've done some more testing.

#1243064

Thanks for keeping me informed.

#1243392

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Richard

I've been able to replicate the issue on my own local test site, and it seems to have been introduced in Access 2.7.

I've escalated it so that it can be debugged and passed to the developers to fix.

I'll keep you posted.

#1243412

Thanks Nigel, appreciate your help.

#1243918

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Richard

I hear that a fix for this should be included in an Access hotfix which is planned for release on Monday.

#1243975

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Richard

If you can't wait, there is an erratum published with a patch that you can apply.

If you subscribe to that erratum you'll be notified when the fix is out, so we are probably done here.

#1244028

My issue is resolved now. Thank you!

#1246319

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Richard

I'm just making sure you received notice about the release of Access which resolved this issue.

#1246451

Thanks Nigel.