Make WordPress Core

Opened 9 months ago

Last modified 7 months ago

#64556 new defect (bug)

Tools -> Export | Failure when setting category

Reported by: kbpcit Owned by:
Priority: normal Milestone: Awaiting Review
Component: Export Version: 6.9
Severity: normal Keywords: has-patch
Cc: Focuses:

Description

Hi,

Export of posts fails when exporting posts of a specific category. This probably has affect on other export settings as well.

File /wp-admin/includes/export.php, line 543 is supposed to echo the slug of the current category's parent. It is trying to get that data from the $cats variable, which normally contains all the categories, but it does not contain that data when limiting the posts to export to a specific category.

Current line 543:

<wp:category_parent><?php echo wxr_cdata( $c->parent ? $cats[ $c->parent ]->slug : '' ); ?></wp:category_parent>

Suggested fix:

<wp:category_parent><?php echo wxr_cdata( $c->parent && isset( $cats[ $c->parent ] ) ? $cats[ $c->parent ]->slug : '' ); ?></wp:category_parent>

Blessings,

Klaas

Attachments (1)

64556.diff​ (999 bytes ) - added by abhishekfdd 7 months ago.

Download all attachments as: .zip

Change History (2)

@abhishekfdd
7 months ago

#1 @abhishekfdd
7 months ago

  • Keywords has-patch added; needs-patch removed

The issue is that when exporting posts filtered by a specific category, the $cats array is only populated with the categories relevant to the export — not all categories. If a category has a parent that isn't in $cats, accessing $cats[ $c->parent ] triggers an undefined index error.
The fix adds an isset() guard before accessing the parent in the $cats array. I've also applied the same fix to the wp:term_parent line which has the identical problem with the $terms array when exporting filtered custom taxonomy terms.
Attaching patch: 64556.diff

Note: See TracTickets for help on using tickets.