WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 10 months ago

#17920 closed enhancement (fixed)

Unnecessary code in wp.getPage

Reported by: nprasath002 Owned by: SergeyBiryukov
Milestone: 4.1 Priority: normal
Severity: minor Version: 3.2
Component: XML-RPC Keywords: has-patch dev-feedback
Focuses: Cc:

Description

Pages Does not have categories

Attachments (2)

wp.getPage.patch (906 bytes) - added by nprasath002 4 years ago.
17920.diff (650 bytes) - added by markoheijnen 10 months ago.

Download all attachments as: .zip

Change History (11)

@nprasath0024 years ago

comment:1 follow-up: @F J Kaiser4 years ago

  • Keywords 2nd-opinion added

But categories can be added to pages.

comment:2 in reply to: ↑ 1 @DrewAPicture4 years ago

Replying to F J Kaiser:

But categories can be added to pages.

Agreed. On one of my sites, pages rely on categories to display specific posts from said categories. At the time it was in deference to creating a new custom post type.

comment:3 @F J Kaiser4 years ago

  • Keywords close added; 2nd-opinion removed

I close it now as I think there are enough use cases for this left.

comment:4 follow-up: @nacin4 years ago

We could wrap this into a post_type_supports check and save the queries.

comment:5 in reply to: ↑ 4 @F J Kaiser4 years ago

Replying to nacin:

We could wrap this into a post_type_supports check and save the queries.

Would this add any performance in- or decrease?

comment:6 @markoheijnen3 years ago

Now there is wp_getPost. I recommend using that instead of wp_getPage. That said I'm not sure how to use post_type_supports. There isn't one for categories, right?

Weird thing is that we expect only categories and not tags or custom taxonomies. I think we should copy the stuff from _prepare_post to _prepare_page and that will solve the issue with a fallback for categories

comment:7 @markoheijnen3 years ago

  • Keywords dev-feedback added; close removed
  • Summary changed from Unnecessary code to Unnecessary code in wp.getPage

Wonder if we can inherit most of the getPost functionality in getPage.

@markoheijnen10 months ago

comment:8 @markoheijnen10 months ago

  • Milestone changed from Awaiting Review to 4.1
  • Type changed from defect (bug) to enhancement

Created a new patch that adds a is_object_in_taxonomy() check. It will prevent one query like this one:

SELECT t.term_id FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('category') AND tr.object_id IN (2) ORDER BY t.name ASC

Moving to 4.1 for consideration.

comment:9 @SergeyBiryukov10 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 29731:

XML-RPC: Check if category support was added for pages before calling wp_get_post_categories() to avoid unnecessary query in wp.getPage.

props markoheijnen, nprasath002.
fixes #17920.

Note: See TracTickets for help on using tickets.