Make WordPress Core

Opened 19 months ago

Closed 19 months ago

Last modified 19 months ago

#55811 closed defect (bug) (invalid)

OrderBy rand in get_posts stopped working after updating to WordPress 6.0

Reported by: itsabhineet's profile itsabhineet Owned by:
Milestone: Priority: normal
Severity: major Version: 6.0
Component: Posts, Post Types Keywords:
Focuses: Cc:

Description

Today after my WordPress site was upgraded to WordPress 6.0, the 'orderby' => 'rand' value started throwing error in the get_posts() function.

Change History (8)

#1 follow-up: @costdev
19 months ago

  • Keywords reporter-feedback added

Hi @itsabhineet, welcome to Trac!

Please comment with the error that you received.

#2 in reply to: ↑ 1 @itsabhineet
19 months ago

This is the error: Object of class stdClass could not be converted to string in .../wp-content/object-cache.php

Replying to costdev:

Hi @itsabhineet, welcome to Trac!

Please comment with the error that you received.

#3 follow-up: @costdev
19 months ago

  • Milestone changed from Awaiting Review to 6.0.1

Milestoning for 6.0.1 for visibility.

@itsabhineet, can you provide any other details, such as:

  • All remaining information provided in the error message/stacktrace.
  • The code block (wrap this in {{{ code here }}}) used for get_posts().
  • Caching plugins that you're using.
  • Whether you can clear the cache and, if so, whether the issue persists/changes/disappears after clearing the cache.

Thanks!

Last edited 19 months ago by costdev (previous) (diff)

#4 in reply to: ↑ 3 @itsabhineet
19 months ago

  • Full stack trace-
PHP Fatal error:  Uncaught Error: Object of class stdClass could not be converted to string in .../wp-content/object-cache.php:1132

Stack trace:
#0 .../wp-content/object-cache.php(1132): array_combine()
#1 .../wp-content/object-cache.php(52): WP_Object_Cache->add_multiple()
#2 .../wp-includes/post.php(7362): wp_cache_add_multiple()
#3 .../wp-includes/post.php(7442): update_post_cache()
#4 .../wp-includes/post.php(7856): update_post_caches()
#5 .../wp-includes/class-wp-query.php(3134): _prime_post_caches()
#6 .../wp-includes/class-wp-query.php(3586): WP_Query->get_posts()
#7 .../wp-includes/post.php(2410): WP_Query->query()
#8 .../wp-content/plugins/...my_plugin_file_01.php: get_posts()
#9 .../wp-includes/template.php(772): require('...')
#10 .../wp-includes/template.php(716): load_template()
#11 .../wp-includes/general-template.php(204): locate_template()
#12 .../wp-content/plugins/...my_plugin_file_02.php: get_template_part()
#13 .../wp-content/plugins/...my_plugin_file_02.php: My_Plugin_Class->function_01()
#14 .../wp-includes/rest-api/class-wp-rest-server.php(1143): My_Plugin_Class->function_02()
#15 .../wp-includes/rest-api/class-wp-rest-server.php(990): WP_REST_Server->respond_to_request()
#16 .../wp-includes/rest-api/class-wp-rest-server.php(414): WP_REST_Server->dispatch()
#17 .../wp-includes/rest-api.php(394): WP_REST_Server->serve_request()
#18 .../wp-includes/class-wp-hook.php(307): rest_api_loaded()
#19 .../wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters()
#20 .../wp-includes/plugin.php(524): WP_Hook->do_action()
#21 .../wp-includes/class-wp.php(398): do_action_ref_array()
#22 .../wp-includes/class-wp.php(770): WP->parse_request()
#23 .../wp-includes/functions.php(1330): WP->main()
#24 .../wp-blog-header.php(16): wp()
#25 .../index.php(17): require('...')
#26 {main}
thrown in .../wp-content/object-cache.php on line 1132
  • The code block-
$args = array(
    'post_type'             => 'post',
    'post_status'           => 'publish',
    'posts_per_page'        => 30,
    'ignore_sticky_posts'   => true,
    'meta_key'              => 'some_key',
    'meta_compare'          => 'EXISTS',
    'orderby'               => 'rand'
);

$posts = get_posts( $args );
  • I am using only one plugin- Redis Cache. I cleared the cache, but it is still throwing the error.
  • I also rebooted my server, but the problem persists.

Replying to costdev:

Milestoning for 6.0.1 for visibility.

@itsabhineet, can you provide any other details, such as:

  • All remaining information provided in the error message/stacktrace.
  • The code block (wrap this in {{{ code here }}}) used for get_posts().
  • Caching plugins that you're using.
  • Whether you can clear the cache and, if so, whether the issue persists/changes/disappears after clearing the cache.

Thanks!

Last edited 19 months ago by costdev (previous) (diff)

#5 follow-up: @costdev
19 months ago

@itsabhineet Thanks for this information, it really helps!

I see that the Redis Cache plugin was updated to version 2.0.25 and the latest changelog entry states:

Removed broken wp_cache_add_multiple() function

Have you updated the Redis Cache plugin to version 2.0.25? If not, updating the plugin should hopefully resolve the issue. Let us know 🙂

Otherwise, I'd suggest reaching out to the Redis Cache developers on the support forum so that they can do some digging and find out if the issue lies there.

#6 in reply to: ↑ 5 @itsabhineet
19 months ago

The Redis Cache Plugin is already up-to-date at version 2.0.25 and still throwing error.

However, I just noticed that the error occurs only when the Redis Object Cache is enabled.

Also, this has happened after the WordPress 6.0 update. The same version of Redis Cache Plugin was working fine before the update.

So, it seems that the Redis Cache Plugin has some issues with WordPress 6.0.

Thanks.

Replying to costdev:

@itsabhineet Thanks for this information, it really helps!

I see that the Redis Cache plugin was updated to version 2.0.25 and the latest changelog entry states:

Removed broken wp_cache_add_multiple() function

Have you updated the Redis Cache plugin to version 2.0.25? If not, updating the plugin should hopefully resolve the issue. Let us know 🙂

Otherwise, I'd suggest reaching out to the Redis Cache developers on the support forum so that they can do some digging and find out if the issue lies there.

#7 @tillkruess
19 months ago

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

This certainly is an issue with my plugin and not WordPress core. Let's move this here: https://wordpress.org/support/topic/orderby-rand-in-get_posts-stopped-working-after-updating-to-wordpress-6-0/

#8 @SergeyBiryukov
19 months ago

  • Keywords needs-patch reporter-feedback removed
  • Milestone 6.0.1 deleted

Thanks @tillkruess!

Note: See TracTickets for help on using tickets.