I need to categorize search result of WordPress, I have done that through adding categories to posts and custom post types. Now, only pages are listing without any category, I think it is possible to add category to pages as well, but I am not aware of its consequences.
Kindly you share your thoughts and experience.
Thank you
WordPress doesn’t provides option to create category in pages .
One thing that can be done is modification in search query
This will search you in all the pages only.
Add this hook on some specific conditions, when you want only pages to be displayed in searches.
Other side will be to display everything other than pages . In that you will have to exclude the pages by their ID’s
WordPress does not natively have a global taxonomy which is what you want. Categories in WordPress are tied to blog posts.
To accomplish this, I would use a combination of the incredible
Advanced Custom Fields
(ACF) plugin and modifyingfunctions.php
to add a custom taxonomy to your site and apply it to all of your post-types.Step 1
In functions.php, make a custom taxonomy like this (modify for your needs):
Step 2
With ACF installed, you’ll use the GUI to make a custom field set that contains this taxonomy. Below the custom field set are
rule
options that show you how to apply the custom bit to all of your entities.Step 3
In
page.php
and other templates you can make reference to your taxonomy terms like this:You can now adjust your search template by a true tag that spans all of your types of content.