Taxonomy according through the post type not working

Support MB Custom Post Type Taxonomy according through the post type not working

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #39845
    q51605@gmail.com[email protected]
    Participant

    HI,
    I am trying to create custom taxonomy select box according through the post type.
    It work at the first time add new post.
    But when I publish the post, the taxonomy just went blank and don't have any value in the selector.

    Here is my code:

    https://pastebin.com/qN4sy5Bx

    #39887
    PeterPeter
    Moderator

    Hello,

    Because after publishing the post, there is no parameter post_type in the URL and the code will not work correctly. After publishing the post, there is the post ID in the URL and you can get the post type by using the WordPress function get_post_type().

    For example:

        $prefix = '';
        $post_type = $_GET['post_type'];
        $taxonomy = '';
        $placehold = '';
    
        if( empty( $post_type ) ) {
            $post_id = null;
            if ( isset( $_GET['post'] ) ) {
                $post_id = intval( $_GET['post'] );
            } elseif ( isset( $_POST['post_ID'] ) ) {
                $post_id = intval( $_POST['post_ID'] );
            }
            $post_type = get_post_type( $post_id );
        }
    
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.