• Hello, I have a requirement to build functionality in a WP site so that all posts, FAQs, and documents can be tagged, and so that when one of those tags is clicked on on the site it links to a search page that lists all the items that are tagged with that given tag.

    I’m not really sure what the best approach is to accomplish this. I’m hoping there is a plugin that can accomplish at least part of this functionality. But I guess there are two key questions.

    I know how to tag blog posts, but how can I tag FAQs and documents (media)? I have a plugin that added FAQ as a custom post type, by the way.

    And then how can I get all the items that are tagged with the same tag to show up together on one page when one of the tags is clicked on?

    Any thoughts would be greatly appreciated. Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    Tags can be used for custom post types by using register_taxonomy_for_object_type('post_tag', 'your_cpt'); from within an ‘init’ hook callback.

    Searching for tagged non-posts involves hooking into ‘pre_get_posts’ and checking the current query vars to decide if the query is searching for tagged posts or not. If it is, the ‘post_type’ query var needs to be set as an array of all post types to search for. By default, only post post types are searched for.

    Thread Starter Ben1011

    (@ben1011)

    Thanks so much. Where exactly would I perform these? Functions.php?

    And by ‘checking the current query vars’, you mean WP_query?

    Moderator bcworkz

    (@bcworkz)

    functions.php will work, preferably in a child theme. Or create a simple plugin which could contain other future custom modifications.

    When you hook ‘pre_get_posts’, your callback is passed the current WP_Query object, let’s use $wp_query as an example. You can check the tag query var with $wp_query->get('tag') and set the post type query var with something like $wp_query->set('post_type', array('post', 'page', 'your_cpt')). You can set any query var this way, using class WP_Query parameter nomenclature.

    Thread Starter Ben1011

    (@ben1011)

    Great, thanks so much. Got sidetracked with something so still haven’t had a chance to try this yet, but I’ll let you know how it goes.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Tagging Posts, FAQs, and Documents’ is closed to new replies.