#129779 Show portfolio category in wordpress posts tab

Landing Forums Jupiter WordPress Theme Show portfolio category in wordpress posts tab

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • Maik Antonio

    Hi, I’m trying to add a category row in the wordpress portfolio posts table, but I wouldn’t want to use a plugin for this action.

    I made a code, added the line but the information didn’t load, could you help me?

    
    
    /* Adcionar categoria no portifolio*/
    
    add_filter('manage_edit-portfolio_columns', 'my_columns');
    function my_columns($columns) {
        $columns['portfolio_category'] = 'Categoria';
    return $columns;
    }
    
    add_action( 'manage_article_portfolio_custom_column', 'my_manage_portfolio_columns', 10, 2 );
    
    function my_manage_portfolio_columns( $column, $post_id ) {
    global $portfolio;
    
    switch( $column ) {
    
        /* If displaying the 'article_category' column. */
        case 'portfolio_category' :
    
            /* Get the genres for the post. */
            $terms = get_the_terms( $post_id, 'portfolio_category' );
    
            /* If terms were found. */
            if ( !empty( $terms ) ) {
    
                $out = array();
    
                /* Loop through each term, linking to the 'edit posts' page for the specific term. */
                foreach ( $terms as $term ) {
                    $out[] = sprintf( '<a href="%s">%s</a>',
                        esc_url( add_query_arg( array( 'portfolio-type' => $post->portfolio_type, 'portfolio_category' => $term->slug ), 'edit.php' ) ),
                        esc_html( sanitize_term_field( 'categoria', $term->category, $term->term_id, 'portfolio_category', 'display' ) )
                    );
                }
    
                /* Join the terms, separating them with a comma. */
                echo join( ', ', $out );
            }
    
            /* If no terms were found, output a default message. */
            else {
                _e( 'No Articles' );
            }
    
            break;
    
        /* Just break out of the switch statement for everything else. */
        default :
            break;
    }
    }
    
    
    Mohsin Al-Rabieai Support Team

    Hi Maik,

    You had some issues with the code. I corrected them to this:

    /* Adcionar categoria no portifolio*/
    
    add_filter('manage_edit-portfolio_columns', 'my_columns');
    function my_columns($columns) {
        $columns['portfolio_category'] = 'Categoria';
    return $columns;
    }
    
    add_action( 'manage_portfolio_posts_custom_column', 'my_manage_portfolio_columns', 10, 1 );
    
    function my_manage_portfolio_columns( $column ) {
    global $post;
    
    switch( $column ) {
    
        /* If displaying the 'article_category' column. */
        case 'portfolio_category' :
            /* Get the genres for the post. */
            $terms = get_the_terms( $post->ID, 'portfolio_category' );
    
            /* If terms were found. */
            if ( !empty( $terms ) ) {
    
                $out = array();
    
                /* Loop through each term, linking to the 'edit posts' page for the specific term. */
                foreach ( $terms as $term ) {
                    $out[] = sprintf( '<a href="%s">%s</a>',
                        get_edit_term_link($term->term_id),
                        $term->name )
                    ;
                }
    
                /* Join the terms, separating them with a comma. */
                echo join( ', ', $out );
            }
    
            /* If no terms were found, output a default message. */
            else {
                _e( 'No Articles' );
            }
    
            break;
    
        /* Just break out of the switch statement for everything else. */
        default :
            break;
    }
    }

    You can now see that the taxonomies are showing up in your portfolio lists.

    Bests

    Maik Antonio

    Muito Obrigado Mohsin, me ajudou muito!!

    Thank you very much Mohsin, it helped me a lot !!

    Nodari Support Team

    You are welcome Maik

    I will mark this case as a resolved

    Have a nice weekend

Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.
Login