[wp-trac] [WordPress Trac] #56992: The Loop displays incorrect data for queries started with `fields => 'id=>parent'`.

WordPress Trac noreply at wordpress.org
Tue Mar 11 10:47:37 UTC 2025


#56992: The Loop displays incorrect data for queries started with `fields =>
'id=>parent'`.
--------------------------------------+----------------------------
 Reporter:  peterwilsoncc             |       Owner:  peterwilsoncc
     Type:  defect (bug)              |      Status:  reopened
 Priority:  normal                    |   Milestone:  6.8
Component:  Query                     |     Version:  3.1
 Severity:  normal                    |  Resolution:
 Keywords:  2nd-opinion dev-feedback  |     Focuses:  performance
--------------------------------------+----------------------------

Comment (by SirLouen):

 Replying to [comment:33 peterwilsoncc]:
 > You're right, there is a work-around without touching WP Core but that's
 not really satisfactory. Requiring developers to work around a bug is not
 a good approach, as many developers will not know to work around it.

 I was here using the Yoast's content faker as you recommended, and I
 noticed something:
 After issuing the WP_Query with `id=>parent` I could perfectly retrieve
 title, URL, content and time with `get_the_title`, `get_permalink`,
 `get_post` and `get_the_time` respectively

 === Environment
 - WordPress: 6.7.2
 - PHP: 8.2.27
 - Server: Apache/2.4.62 (Debian)
 - Database: mysqli (Server: 11.4.5-MariaDB-ubu2404 / Client: mysqlnd
 8.2.27)
 - Browser: Chrome 134.0.0.0
 - OS: Windows 10/11
 - Theme: Twenty Twenty-Five 1.0
 - MU Plugins: None activated
 - Plugins:
   * Hierarchical Page Navigator 1.0.1
   * Test Reports 1.2.0

 This is the modified function in my plugin (link to code in my previous
 answer), that includes all this:
 {{{#!php
 <?php
 private function display_page_tree($parent_id, $page_children,
 $current_depth, $max_depth) {
         if ($max_depth > 0 && $current_depth > $max_depth) {
             return;
         }

         if (isset($page_children[$parent_id])) {
             echo '<ul class="page-level-' . ($current_depth - 1) . '">';

             foreach ($page_children[$parent_id] as $page_id) {
                 $page_title = get_the_title($page_id);
                 $page_url = get_permalink($page_id);
                 $page_the_content = get_post($page_id)->post_content;
                 $page_time = get_the_time('Y-m-d H:i:s', $page_id);

                 echo '<li class="page-item page-item-' . $page_id . '">';
                 echo '<a href="' . esc_url($page_url) . '">' .
 esc_html($page_title) . '</a>';
                 echo '<p>' . esc_html($page_the_content) . '</p>';
                 echo '<p>' . esc_html($page_time) . '</p>';

                 // Recursively display children
                 $this->display_page_tree($page_id, $page_children,
 $current_depth + 1, $max_depth);

                 echo '</li>';
             }

             echo '</ul>';
         }
     }

 }}}

 So, adding on top of all the comments in my previous messages, now I can't
 see the problem you are stating in this report. With the ID you have
 access to all the resources for each post. Forcefully bringing all the
 info doesn't bring any additional value except for an unnecessary
 performance impact as I reported in my tests.

 I think someone else should come, read this conversation, test and add a
 2nd-opinion.

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


More information about the wp-trac mailing list