[wp-trac] [WordPress Trac] #57491: Php 8.2.0 - error if the Wp Query does not have any post

WordPress Trac noreply at wordpress.org
Fri May 12 12:08:31 UTC 2023


#57491: Php 8.2.0 -  error if the Wp Query does not have any post
---------------------------+------------------------------
 Reporter:  davidki        |       Owner:  (none)
     Type:  defect (bug)   |      Status:  new
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Query          |     Version:  6.1.1
 Severity:  major          |  Resolution:
 Keywords:  needs-testing  |     Focuses:
---------------------------+------------------------------

Comment (by sonko):

 Hi,
 Based on the custom query I'm assuming you have more custom code or some
 plugins installed so I've switched to native taxonomies (category) and
 manually added the `post_wish_count`. I've tested it on PHP 8.2.0 and WP
 6.3 (develop version), Twenty Twenty-Three theme, no additional plugins
 and got no notices. So I guess it was fixed in new version?

 {{{#!php
 <?php
 $args = [
     'post_type' => 'post',
     'post_status' => 'publish',
     'posts_per_page' => 10,
     'ignore_sticky_posts' => 1,
     'orderby' => 'meta_value_num',
     'order' => 'DESC',
     'meta_key' => 'post_wish_count',
     'tax_query' => [
         'relation' => 'AND',
         [
             'taxonomy' => 'category',
             'field' => 'slug',
             'terms' => ['test1111'],
         ],
         [
             'taxonomy' => 'category',
             'field' => 'slug',
             'terms' => 'test22222',
             'operator' => 'NOT IN',
         ],
     ],
 ];
 $query = new WP_Query($args);

 if ( $query->have_posts() ) {
     foreach ($query->get_posts() as $post) {
         echo "{$post->post_title} <br>";
     }
 } else {
     echo "Nothing found";
 }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57491#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list