-
Notifications
You must be signed in to change notification settings - Fork 25
Fix post tags missing from export when using --post__in filter #131
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
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix post tag stripped from posts during wp export
Add test coverage and error handling for post tag export with --post__in
Jan 14, 2026
This comment was marked as resolved.
This comment was marked as resolved.
Use get_post() to ensure we have a proper WP_Post object before retrieving terms. This ensures wp_get_object_terms() can correctly access term relationships that may not be available on raw database objects. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
Copilot
AI
changed the title
Add test coverage and error handling for post tag export with --post__in
Fix post tags missing from export when using --post__in filter
Jan 14, 2026
This comment was marked as resolved.
This comment was marked as resolved.
Instead of relying on wp_get_object_terms() which may have cache issues with posts retrieved directly from the database, query the term_relationships table directly and then fetch full term objects. This ensures term relationships are always retrieved correctly regardless of cache state. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Switched from direct database queries to WordPress native get_the_terms() function. This function properly retrieves terms for each taxonomy while respecting WordPress's post context set up by setup_postdata(). Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Convert database post object to WP_Post using get_post() before setting up post context. This ensures get_the_terms() has access to properly initialized post data with term relationships loaded. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Call update_object_term_cache() to ensure term relationships are loaded into cache before calling get_the_terms(). This resolves the issue where posts fetched directly from the database don't have their term relationships cached. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Reverted to simpler approach using wp_get_object_terms() with proper error handling. Added clean_post_cache() call to ensure fresh term data is retrieved, avoiding any stale cache issues. Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
This comment was marked as resolved.
This comment was marked as resolved.
Must be a slug for tags
2 tasks
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When exporting posts with
--post__in, tags appear in the<wp:tag>header section but are missing from individual post items where they should appear as<category domain="post_tag">elements. This prevents proper tag association on import.Root Cause
Posts retrieved directly from the database using
SELECT * FROM wp_postsmay have stale or missing cache data for term relationships. Whenwp_get_object_terms()is called, it may rely on cached data that doesn't exist or is stale for posts fetched via raw SQL queries, resulting in empty term arrays even though the relationships exist in the database.Changes
clean_post_cache()before retrieving terms withwp_get_object_terms()WP_ErrorhandlingThis approach uses WordPress native functions exclusively. The key is calling
clean_post_cache()to clear any stale cached data before retrieving terms, ensuring fresh term relationships are fetched from the database.The existing "Export categories, tags and terms" test only validated header presence, missing the critical per-post validation. The new test fills this gap and validates the complete fix.
Testing
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.