• Resolved Sanapaino

    (@sanapaino)


    Welcome to WordPress 5, Require Post Category. Version 2 does the job with posts but I have difficulties to get it working with custom post types and custom taxonomies. Show_in_rest is enabled but other than that I have no idea how to debug.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Josh Hartman

    (@joshhartman)

    When on a post of the type that you are expecting to see the notices, open your developer console and check the contents of require_post_category.taxonomies for your custom taxonomy.

    And make sure when you register your taxonomy that you associate it with your post type using the object_type argument.

    Also, please paste your code where you are using the rpc_post_types filter to add your requirements.

    Thread Starter Sanapaino

    (@sanapaino)

    Thanks but no luck yet. Console shows the Object: { message: “Choose this…”} but the UI shows nothing.

    Here’s how I unset for post and try to set for custom_post and page:

    // require post category on custom post type
    function custom_rpc_post_types( $post_types ) {
    	unset($post_types['post']);
    	$post_types['custom_post'] = array( 'custom_cat' => array(
    			'message' => "Choose this..."
    		) );
    	$post_types['page'] = array( 'custom_cat' => array(
    			'message' => "Choose that..."
    		) );
    	return $post_types;
    }
    add_filter( 'rpc_post_types', 'custom_rpc_post_types' );
    • This reply was modified 4 years, 9 months ago by Sanapaino.
    Plugin Author Josh Hartman

    (@joshhartman)

    Tested and that code is working. I created a custom_cat taxonomy, assigned it to the page post type. Opened a page for editing and I have a notice that says “Choose that…”.

    Screenshot

    And the require_post_category.taxonomies JavaScript object displays like this:

    custom_cat:
        message: "Choose that..."
        type: "hierarchical"

    Screenshot

    Possible plugin conflict on your installation?

    • This reply was modified 4 years, 9 months ago by Josh Hartman.
    • This reply was modified 4 years, 9 months ago by Josh Hartman.
    Thread Starter Sanapaino

    (@sanapaino)

    Sorry, no. I’ve tried with and without any (other) plugins and in three different themes (incl. default 2020) and three different installations in public and local servers. And four browsers. For post with standard categories everything is fine but custom posts or taxonomies, no.

    Plugin Author Josh Hartman

    (@joshhartman)

    Hmmm. Well I dug deeper and found an issue. So, if you register a taxonomy from scratch and don’t set a rest_base it will return false, but I was testing with taxonomies created with Custom Post Types UI which has a default rest_base of null. So I needed to check for both in my code to make sure there is not a custom rest_base set.

    Please update to v2.0.2 and try it out. Thanks!

    Thread Starter Sanapaino

    (@sanapaino)

    Yes! That did the trick. Thank you.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Problem with custom post type & custom taxonomy’ is closed to new replies.