WordPress.org

Forums

Custom Post Type UI
[resolved] Show custom posts in category archives and in own archives (17 posts)

  1. nemoprofeta
    Member
    Posted 2 years ago #

    I am able to easily access the archive page for my custom posts. However I wanted to show custom posts inside "normal" category archives. So I used this code:

    function my_get_posts( $query ) {
    	if ( is_feed()||is_archive()&&false == $query->query_vars['suppress_filters'])
    		$query->set( 'post_type', array( 'post', 'progetto' ) );
    	return $query;
    }
    add_filter( 'pre_get_posts', 'my_get_posts' );

    It works, but it makes the custom post archives empty.
    What's the best way to have both?

    http://wordpress.org/extend/plugins/custom-post-type-ui/

  2. Michael Beckwith
    Member
    Plugin Author

    Posted 2 years ago #

    I'd consider a brand new wp_query call instead of altering the original query.

  3. nemoprofeta
    Member
    Posted 2 years ago #

    Thanks, what do you mean?

  4. Michael Beckwith
    Member
    Plugin Author

    Posted 2 years ago #

    Maybe I was a little bit confused. Were you trying to show 2 separate loops inside the 1 template? or trying to pull the two post types into 1 query.

  5. nemoprofeta
    Member
    Posted 2 years ago #

    Mmm, I don't remember, 6 months are too much.

  6. Michael Beckwith
    Member
    Plugin Author

    Posted 2 years ago #

    I'll assume resolved and just mark as such then.

  7. msbree
    Member
    Posted 2 years ago #

    I *think* I have the same issue! I've selected appropriate blog categories for my 'articles' (custom post type), but they do not show up in the regular blog category archives, even though I have 'Has Achives' set to True.

    In fact, they don't even show up anywhere unless I link them directly.

    I need for them to show up in the regular blog category archives, along with the regular blog posts in the same category!

    HELP! Thanks!!!

  8. Michael Beckwith
    Member
    Plugin Author

    Posted 2 years ago #

    msbree, I do believe you will have to add the custom post type to the query parameters for the category archive.

    Try out this snippet from Chris Coyier and see if it helps.

    function myprefix_add_custom_types( $query ) {
      if( is_category() && empty( $query->query_vars['suppress_filters'] ) ) {
        $query->set( 'post_type', array(
         'post', 'your-custom-post-type-here'
    		));
    	  return $query;
    	}
    }
    add_filter( 'pre_get_posts', 'myprefix_add_custom_types' );

    http://css-tricks.com/snippets/wordpress/make-archives-php-include-custom-post-types/

  9. msbree
    Member
    Posted 2 years ago #

    Michael...you are awesome with your prompt reply! Thank you!!!

    I will try the one from Chris Coyier first and see how that goes!

    I did find another thread here with a different code that might do the same thing, but it's two years old.

    http://wordpress.org/support/topic/custom-post-type-ui-and-catagories-and-tags-not-working?replies=10

    I'll post my update here, so others can use this information!
    thanks again!!!

  10. Michael Beckwith
    Member
    Plugin Author

    Posted 2 years ago #

    I'd go with Coyier's code first, as I know it's a current hook that's available.

  11. msbree
    Member
    Posted 2 years ago #

    Well I tried it Michael, and the code did bring in my Custom Post Type into the regular blog categories; unfortunately, it brought the entire post into the Category Archive and not just the excerpt! So code removed! :(

  12. Michael Beckwith
    Member
    Plugin Author

    Posted 2 years ago #

    I'd check on your theme template files for that, as it's not something that the plugin would be in control of. The plugin doesn't do anything regarding display of the post types/taxonomies, it just makes them available to be used. So I think you were a step closer, you just need to amend some other parts elsewhere in the site.

  13. msbree
    Member
    Posted 2 years ago #

    I tried it again Michael, and included an excerpt in a 'test' article...no dice! In fact, my main nav bar disappeared too, so I removed the code.

    No worries...I will either redo all of these 133 articles as regular posts (arrgghhhh) or hire someone to do this for me! Or maybe I can figure out how to move them all to the regular posts database!

    Anything beyond copying and pasting simple code into a file is out of my league, when it comes to php! lol

    Thanks so much anyway...I appreciate your trying to help!

    Hey, have a great Memorial Day weekend! :)

  14. Michael Beckwith
    Member
    Plugin Author

    Posted 2 years ago #

    I don't think it's going to be that drastic of a measure. There are functions in your theme files that control the length of post that get displayed. It's nothing related to the content in the database. Look for instances of the_content() vs the_excerpt() inside your loops.

  15. msbree
    Member
    Posted 2 years ago #

    Well I took the real easy way out on this one! I used a plugin to move the custom posts to the regular posts, and it worked like a charm, so I'm good for now!

    When the time comes for more customization, I will have a developer figure this out for me, as I'll probably have use for custom post types down the road!

    Thanks again Michael!

  16. Szyam
    Member
    Posted 2 years ago #

    Hello guys. I'm kind of having a similar issue? I have a CPT called "reviews" which has 2 taxonomies, "Format" and "Origin". Under those taxonomies I have created 2 formats and 2 origins, so in the post editor I have a box labeled "Format" which has 'single' and 'album' as well as a box for "origin" which contains 'import' and 'domestic'.

    Everything is working well, Im calling the CPTs with a WP_query, and echoing out the Taxonomies, however when I click on the 'single' or 'album' or 'import' or 'domestic' link, it opens an archive.php page to display the taxonomies.

    I have hierarchy set to 'true' on the CPT and the taxonomy. I've tried using the above snippet from css-tricks. I've renamed the archive.php a ton of various different names like 'archive-format.php', 'archive-format_single.php' etc etc...

    Anything I'm missing here?

    Also, when I go to the CPT/Taxonomy section in the dashboard I get this error while in debug mode:

    Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/detroitsounds/wp-content/themes/DetroitSounds-theme/functions.php(353) : regexp code on line 1
    
    Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/detroitsounds/wp-content/themes/DetroitSounds-theme/functions.php(353) : regexp code on line 1
    Popular Format

    Thats while in the 'Reviews'/'Format' section...

    Cheers on any ideas...

  17. Michael Beckwith
    Member
    Plugin Author

    Posted 2 years ago #

    Not sure what's not going right regarding your taxonomy links. All I know about WordPress says clicking the taxonomy terms should go to an archive listing of the term.

    Hierarchical on CPTs would mean you could make one a child of another, very much like you can have child pages of other pages. I imagine it's very much the same with taxonomies, and can be used for more levels of terms.

    Regarding the last part, not sure that's related to this plugin at all.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Custom Post Type UI
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic