• Resolved Fi Fi P

    (@fi-fi-p)


    I created a custom post type for my projects and later needed to add tags and categories to the info, code below:

    // Creates Projects post type
    
    register_post_type('projects', array(
    'label' => 'Projects',
    'public' => true,
    'show_ui' => true,
    'capability_type' => 'post',
    'hierarchical' => false,
    'rewrite' => array('slug' => 'projects'),
    'query_var' => true,
    'supports' => array(
    'title',
    'editor',
    'excerpt',
    'trackbacks',
    'custom-fields',
    'comments',
    'revisions',
    'thumbnail',
    'author',
    'page-attributes'),
    'taxonomies' => array('category', 'post_tag') // this is IMPORTANT
    ) );
    
        add_action('init', 'projects_add_default_boxes');
    
        function projects_add_default_boxes() {
        register_taxonomy_for_object_type('category', 'projects');
        register_taxonomy_for_object_type('post_tag', 'projects');
        }

    [Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]

    This worked great and my new tags appeared straight away in my footer widget…..but when clicked I get a ‘nothing found’ message and it doesn’t link to the project? Have I missed out a step?!

    https://wordpress.org/plugins/wp-category-tag-could/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author benohead

    (@benohead)

    Hi,

    The problem is actually that WordPress will only consider posts in the search, category and tag pages, not your custom post type (and is thus not caused by this plugin).

    In order to have them displayed, you’ll have to add the following:

    add_action( 'pre_get_posts', 'projects_add_custom_post_types' );
    
    function projects_add_custom_post_types( $query ) {
    	if ( $query->is_search || $query->is_tag || $query->is_category ) {
    		$query->set( 'post_type', array( 'post', 'projects' ) );
    	}
    }

    Hope this helps you solve your problem and enjoy the plugin.

    Thread Starter Fi Fi P

    (@fi-fi-p)

    Perfect! Thank you so much for your help x

    Plugin Author benohead

    (@benohead)

    You’re welcome. Don’t forget to review the plugin if you like it !

    Hi Benohead,
    where would i add the code you provide above? I too am using a couple of custom post types.

    Thanks

    Plugin Author benohead

    (@benohead)

    You should add this either to functions.php in your theme or create a small plugin which contains this code.

    added the code to my functions.php of my theme:

    function add_custom_post_types( $query ) {
    	if ( $query->is_search || $query->is_tag || $query->is_category ) {
    		// print_r($query->query_vars);
    		$query->set( 'post_type', array( 'post', 'custom1','custom2' ) );
    		// echo "after set<br>";
    		print_r($query->query_vars);
    	}
    }
    add_action( 'pre_get_posts', 'add_custom_post_types' );

    also, only one item of type custom1 is returned when I select a tag. Here is the print_r of the $query_vars on the Tag Archive page:

    Array
    (
        [tag] => lagarde
        [error] =>
        [m] =>
        [p] => 0
        [post_parent] =>
        [subpost] =>
        [subpost_id] =>
        [attachment] =>
        [attachment_id] => 0
        [name] =>
        [static] =>
        [pagename] =>
        [page_id] => 0
        [second] =>
        [minute] =>
        [hour] =>
        [day] => 0
        [monthnum] => 0
        [year] => 0
        [w] => 0
        [category_name] =>
        [cat] =>
        [tag_id] =>
        [author] =>
        [author_name] =>
        [feed] =>
        [tb] =>
        [paged] => 0
        [comments_popup] =>
        [meta_key] =>
        [meta_value] =>
        [preview] =>
        [s] =>
        [sentence] =>
        [fields] =>
        [menu_order] =>
        [category__in] => Array
            (
            )
    
        [category__not_in] => Array
            (
            )
    
        [category__and] => Array
            (
            )
    
        [post__in] => Array
            (
            )
    
        [post__not_in] => Array
            (
            )
    
        [tag__in] => Array
            (
            )
    
        [tag__not_in] => Array
            (
            )
    
        [tag__and] => Array
            (
            )
    
        [tag_slug__in] => Array
            (
                [0] => lagarde
            )
    
        [tag_slug__and] => Array
            (
            )
    
        [post_parent__in] => Array
            (
            )
    
        [post_parent__not_in] => Array
            (
            )
    
        [author__in] => Array
            (
            )
    
        [author__not_in] => Array
            (
            )
    
        [post_type] => Array
            (
                [0] => post
                [1] => custom1
                [2] => custom2
            )
    
    )

    when I used the code, I would get 10 items from what seemed to be limited to the first custom post type listed in:
    $query->set( ‘post_type’, array( ‘post’, ‘custom1′,’custom2’ ) );

    When I remove the code I do get 2 post items which were tagged with the tag in question. And testing for a tag that is only on custom type entries come up with a page not found.

    this definitely doesnt seem like a problem with your plugin, but the suggested code does not seem to work either. Any help would be appreciated.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Tag Cloud links not finding page’ is closed to new replies.