Support Forum
Support › MB Term Meta › ONLINE/OFFLINE state for any post of a CPT
Hello Peter and the team!
I would like to get your opinion on the best way to handle situations where certain posts of a Custom Post Type (CPT) need to be transitioned at any time from ONLINE to OFFLINE (considering that this OFFLINE status can be either temporary or permanent, depending on the posts).
For now, I have thought that I could create a Custom Field (CF) or a Taxonomy called "LIVE" with only 2 possible values: 1 (ONLINE) and 0 (OFFLINE).
This way, I can change the value of a specific post at any time, and on the front end, I would have made sure beforehand to only display on my archive pages the posts that have the value 1 for this CF or taxonomy.
But then, I have several questions:
1. Taxonomy or CF? According to your article comparing them, it seems I should choose Taxonomy because the latter is the way to go to filter posts. So unless you have another suggestion on how to proceed that I haven't thought of, I guess I should go that route.
2. If I choose taxonomy and have multiple CPTs for which I want to apply the same ONLINE/OFFLINE functionality, is it okay if I use the same taxonomy field? No risk of interference between CPTs at any given time or change?
3. From an SEO perspective, I'm wondering if it's more relevant to display a 404 error or to redirect (via Slim SEO) the post set to OFFLINE status to the CPT or a parent page. The latter would be more relevant for the user, but I believe I read once that search engines prefer 404s to 301 redirects in this kind of situation.
4. If you suggest displaying a 404 error, how do I do it? Do I switch the post in question to draft mode in the WP back office?
5. But in the case I can do so, can I simply use the "Published/Draft" status of a CPT post to display only the posts with the "Published" status on my archive pages?
As you can see, I'm quite lost so thank you in advance for your invaluable feedback!
Laurent
Hello Laurent,
1, 2. You can use a custom field or taxonomy, both ways are ok.
3. Yes, from an SEO perspective, I think you should redirect the offline posts to a valid URL. Following this article https://yoast.com/seo-anti-patterns-301-redirect-all-your-404s-to-your-homepage/
4, 5. You can follow this topic to use some custom code to exclude the offline posts from the default query https://stackoverflow.com/questions/29890473/how-do-i-show-hide-a-wordpress-post-description-or-any-other-field-on-the-front
Thank you Peter. Your reply left me in doubt on several aspects so I asked ChatGPT and this is what it had to say (I think it might be useful to other members).
-----
"Handling the transition of posts from ONLINE to OFFLINE in a Custom Post Type (CPT) involves several considerations. Let's address your questions step by step:
1. Taxonomy or Custom Field (CF)?
For your use case, a taxonomy seems more suitable since it's designed for grouping and categorizing content. In this scenario, a taxonomy with two terms (ONLINE and OFFLINE) would allow you to easily filter and query posts based on their status.
(@Peter: I'm surprised your reply both because your article comparing CF and taxonomy explictly says:
- Do you need to browse posts by value? NO => CF | YES => Taxonomy
- Do you need to filter by the value? NO => CF | YES => Taxonomy
- Do you need to manage (add, edit, remove) the values? NO => CF | YES => Taxonomy
Link: https://metabox.io/custom-fields-vs-custom-taxonomies/)
2. Using the Same Taxonomy for Multiple CPTs
Yes, it's absolutely fine to use the same taxonomy across multiple CPTs. Taxonomies are meant to be flexible and can be shared among different post types without interference.
3. SEO Considerations - 404 or Redirect
In terms of SEO, it's generally better to avoid 404 errors for content that has been intentionally removed or set to OFFLINE. A 301 redirect would be more user-friendly and can help retain SEO value by directing users and search engines to relevant content. However, the decision depends on your specific use case and how you want to handle the user experience.
4. How to Display a 404 Error
If you decide to go with the 404 approach, switching the post to draft mode in the WordPress back office is one way to achieve this. Drafted posts are not publicly accessible, and attempting to access them would result in a 404 error.
5. Filtering Published/Draft Status in Archive Pages
Yes, you can filter posts based on their published status. In your archive page queries, you can specify that only published posts should be displayed. For example, in a typical WP_Query or get_posts() call, you can include the 'post_status' parameter 'post_status' => 'publish'.
This ensures that only published posts are retrieved.
In summary, using a taxonomy for the ONLINE/OFFLINE status seems like a reasonable choice. The decision between a 404 error and a redirect depends on your specific UX goals. Combining taxonomies with proper post status queries in your template files will help you achieve the desired functionality on the front end."