Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Hi @emirandah

    Just to confirm, you’re able to successfully associate one to many of the categories with the published post types posts, correct? The only issue is seeing them alongside the other posts for the given category archive?

    Just in case, I’d recommend using this version below. It only adds the post types to the category archives, not the post_tags too. You’ll want to fill in these $cptui_post_types = array( 'my_post_type', 'my_other_post_type', 'my_third_post_type' ); with your own slugs.

    function my_cptui_add_post_types_to_archives( $query ) {
    	// We do not want unintended consequences.
    	if ( is_admin() || ! $query->is_main_query() ) {
    		return;    
    	}
    
    	if ( is_category() && empty( $query->query_vars['suppress_filters'] ) ) {
    
    		// Replace these slugs with the post types you want to include.
    		$cptui_post_types = array( 'my_post_type', 'my_other_post_type', 'my_third_post_type' );
    
    		$query->set(
    	  		'post_type',
    			array_merge(
    				array( 'post' ),
    				$cptui_post_types
    			)
    		);
    	}
    }
    add_filter( 'pre_get_posts', 'my_cptui_add_post_types_to_archives' );
    

    Lastly, where did you put the snippet of code at? In your active theme’s or child theme’s functions.php file?

    Thread Starter emirandah

    (@emirandah)

    Hi, yes, I am able to add the old categories to the new post types. I just can’t see the new post types if I try to view a category archive. I did make sure the archive option was checked in the new post type.

    I’m not really familiar with code, but I put the snippet at the very bottom of the theme functions (functions.php). I don’t think I have any other themes, but it was definitely in the Freya file.

    Something seems to be wrong though. After I add the code, I see two lines displaying the code along the top of some of the pages of my site, and also on the dashboard. Am I doing something wrong?

    Thread Starter emirandah

    (@emirandah)

    Here is an example: https://adrianjameshernandez.com/wyg/wyg-introduction/
    This post is the new post type, “wyg”. It shares categories with regular WP posts, but if I try to view any of those category archives, the wyg post type doesn’t appear.

    Thread Starter emirandah

    (@emirandah)

    I also noticed after I added the snippet that it’s affecting my sidebar widget. If the snippet is added, I can’t add new menus to my sidebar. I just see the snippet text instead of the menu options.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I’m assuming you undid it since, as I’m not seeing that.

    It sounds like you were maybe adding it outside of <?php and ?> PHP tags.

    So, we’ll try a custom plugin quick with that wyg post type in place, but only that one at the moment.

    https://www.dropbox.com/s/8baaex3zjluuyyk/cptui-support.zip?dl=0

    should be able to be uploaded and extracted and installed like a normal plugin for ya. You can extract ahead of time to peak at the code just in case needed.

    Thread Starter emirandah

    (@emirandah)

    Sorry, yes, I did undo it, unfortunately on accident. I actually cut the snippet and thought to add it above the ?>, but I think I messed something up. I’m seeing some error messages in the file that weren’t there before, and I’m not sure what I need to delete.

    Is there a way to share a screenshot with you?

    • This reply was modified 4 years, 10 months ago by emirandah.
    Thread Starter emirandah

    (@emirandah)

    Thread Starter emirandah

    (@emirandah)

    It’s telling me I don’t have admin privileges, but I just checked my account, and I am logged in as an admin.

    Thread Starter emirandah

    (@emirandah)

    I did install the plugin you sent, and it worked perfectly. Can you tell me where I should be pasting the snippet to get it working for other new posts types? I have two others right now, but I plan to make more, so I should learn to do this.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I’ll never be able to push out any sort of update for this quick plugin, so may as well just re-use it for the other two post types.

    Replace array( 'wyg' ); with array( 'wyg', 'my_other_post_type', 'my_third_post_type' );

    Don’t forget to change the “my_other_post_type” and “my_third_post_type” to your other two slugs.

    Thread Starter emirandah

    (@emirandah)

    That worked perfectly. Thank you for your help!

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Welcome ??

    Thread Starter emirandah

    (@emirandah)

    Hello again, I just migrated from Freya to Astra, and I am not able to view custom post types within the archives again. I noticed the plugin states it has not been tested with my current version of WordPress. Can you please tell me if the plugin works with Astra? Or if there is anything I need to add to get the archives working again?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    All the sample code I typed up previously should be theme agnostic and not tied to any set one theme. Same thing for Custom Post Type UI. It’s all dependent on WordPress core code that would be available regardless. So it’s hard to say exactly why it’s suddenly not working unless something somehow is overriding other things.

    Thread Starter emirandah

    (@emirandah)

    That’s what I had thought. Do you have any other ideas on what to check? The only change I made was installing Astra. I also noticed that the blog options I made in Astra are not displaying on the custom post types either–it doesn’t show categories and tags at the top of custom post types like it does on regular post types.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘Trouble applying code for catagories’ is closed to new replies.