Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add conditional for CPT archives and CPT term archives #328

Merged
merged 17 commits into from
Sep 27, 2021

Conversation

mikeyarce
Copy link
Contributor

@mikeyarce mikeyarce commented May 27, 2021

Description

When you register a custom post type with a taxonomy, the archive pages don't have the right metadata, they pick up the metadata from the first item in the loop instead of the main archive page.

What I'm trying here is adding the is_post_type_archive() conditional and switching to getting the queried object instead of just calling get_the_category() as that doesn't work in all cases.

Edit: I found that there's another case that I wanted to target: custom post type taxonomy archives. I've addressed that and added unit tests for that as well.

Fixes #327

Motivation and Context

Fixing this for custom post type archives

How Has This Been Tested?

  1. On your test site, make sure you have a CPT with a category
  2. Also make sure you have a regular post type with a category
  3. Check this PR out to your test site
  4. Go to the Archive pages for both the CPT and the regular post category
  5. Check to see if the right metadata is present for them both.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Question: Should we also check if the post type is currently added to the Parse.ly options?

Change to get queried object instead of category.
@mikeyarce mikeyarce requested a review from a team as a code owner May 27, 2021 23:03
@GaryJones
Copy link
Contributor

This could do with some tests.

@mikeyarce mikeyarce requested a review from htdat June 1, 2021 02:40
@mikeyarce mikeyarce added this to the 2.6.0 milestone Jun 2, 2021
`is_archive()` is better in this case because it also targets taxonomy archives as well as custom post type archives.
@mikeyarce mikeyarce changed the title Add conditional for cpt archives Add conditional for CPT archives and CPT term archives Jun 2, 2021
tests/structured-data/class-archive-post-test.php Outdated Show resolved Hide resolved
tests/structured-data/class-archive-post-test.php Outdated Show resolved Hide resolved
tests/structured-data/class-archive-post-test.php Outdated Show resolved Hide resolved
tests/structured-data/class-archive-post-test.php Outdated Show resolved Hide resolved
tests/structured-data/class-archive-post-test.php Outdated Show resolved Hide resolved
src/class-parsely.php Outdated Show resolved Hide resolved
It doesn’t change the functionality to have a custom post type or not, so to simplify we’ll remove that from the test.
Copy link
Contributor

@GaryJones GaryJones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the condition as you suggested, tweak the test method name as I've now added, and then this is good to land. Thank you Mikey 👍🏻

tests/structured-data/class-archive-post-test.php Outdated Show resolved Hide resolved
Copy link
Contributor

@GaryJones GaryJones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@pauarge
Copy link
Contributor

pauarge commented Sep 24, 2021

I have merged develop into this branch. I kept the changes, but I had to split the tests into two separate files to follow the pattern that we have adopted since we did this PR.

Copy link
Contributor

@pauarge pauarge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@GaryJones GaryJones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor tweaks.

tests/StructuredData/CustomPostTypeArchiveTest.php Outdated Show resolved Hide resolved
tests/StructuredData/CustomPostTypeArchiveTest.php Outdated Show resolved Hide resolved
tests/StructuredData/CustomPostTypeArchiveTest.php Outdated Show resolved Hide resolved
tests/StructuredData/CustomTaxonomyTermArchiveTest.php Outdated Show resolved Hide resolved
tests/StructuredData/CustomPostTypeArchiveTest.php Outdated Show resolved Hide resolved
tests/StructuredData/CustomTaxonomyTermArchiveTest.php Outdated Show resolved Hide resolved
Co-authored-by: Gary Jones <gary.jones@automattic.com>
@pauarge pauarge merged commit e467ae9 into develop Sep 27, 2021
@pauarge pauarge deleted the fix/cpt-categories branch September 27, 2021 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Metadata: Custom Post type category pages don't display the right metadata
3 participants