Post Info don't show on CPT


Hello Thierry,

I'm using the last version of Beans (1.3.1-rc).

I've created a "job" custom post type and a single-job.php template.

Everything works very well, except one thing : post info (date, author, etc.) don't appear by default. Is it a issue/bug ? Or is it normal ? If so, what is the best thing to do ?

Thank you in advance for your help !

Mathieu


Hey Mathieu,

This is an intentional behavior, post meta are only added for the post post type. As for pretty much everything is Beans, it is quite flexible and can easily be added for other post type, in this case using the beans_pre_post_meta filter. If you look at its Code Reference, you will see that it says "True to short-circuit, False to let the function run".

So if you want the post meta to be displayed on all post types (including pages etc.), then you can add the following line in your child theme functions.php

add_filter( 'beans_pre_post_meta', '__return_false' );

This never short-circuit and therefore always display post meta. If you need to apply a condition, then you will need to run a callback as follow:

add_filter( 'beans_pre_post_meta', 'example_pre_post_meta' );

function example_pre_post_meta( $pre ) {

 // Don't short-circuit for 'job' post type.
  if ( 'job' === get_post_type() ) {
    return false;
 }

 return $pre;

}

Some other short-circuit filters are available for other post fragments, you may find all that in the Fragments Post Code Reference or straight in Beans code in lib/templates/fragments/post.php.

Happy coding,


Thanks a lot Thierry. Seems that I've some progress to make in the global understanding of Beans... But I'm working on it ! Thanks again !


You are doing very very well, keep learning and producing awesome stuff 😉

Glad to have you part of the Beans community,


The code will show the default post meta. How would we display Custom Post Type taxonomy category (ies) and tags on the CPT posts? (CPT's are made through CPTUI plugin.)


Mat gave me some very important information on getting this to work: I added two custom post types one called edwien and the other nettmagasin. (Norwegian). Then added the following:

 // Don't short-circuit for 'job' post type.
add_filter( 'beans_pre_post_meta', 'example_pre_post_meta' );

function example_pre_post_meta( $pre ) {
  if ( 'edwien' === get_post_type() ) {
    return false;
 }

 if ( 'nettmagasin' === get_post_type() ) {
    return false;
 }

 return $pre;
}

The custom post type meta did not show up so Mat gave me the following code and I inserted the following:

// Add custom taxonomy.
add_action( 'beans_post_meta_prepend_markup', 'add_event_taxonomy' );
function add_event_taxonomy() {

   $edwiencategories = get_the_terms( get_the_id(), 'edwien-kategori' );
    $edwientags = get_the_terms( get_the_id(), 'edwien-stikkord' );
    $nettmagasincategories = get_the_terms( get_the_id(), 'nettmagasin-kategori' );
    $nettmagasintags = get_the_terms( get_the_id(), 'nettmagasin-stikkord' );

    if ( is_array( $edwiencategories ) ) {
        foreach ( $edwiencategories as $edwiencategory ) {

                echo '<li><a href="' . get_term_link( $edwiencategory->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $edwiencategory->name ) . '" ' . '>' . $edwiencategory->name.'</a></li> ';
        }
    }

    if ( is_array( $edwientags ) ) {
            foreach ( $edwientags as $edwientag ) {

                    echo '<li><a href="' . get_term_link( $edwientag->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $edwientag->name ) . '" ' . '>' . $edwientag->name.'</a></li> '; 
        }
    }

    if ( is_array( $nettmagasincategories ) ) {
            foreach ( $nettmagasincategories as $nettmagasincategory ) {

                    echo '<li><a href="' . get_term_link( $nettmagasincategory->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $nettmagasincategory->name ) . '" ' . '>' . $nettmagasincategory->name.'</a></li> ';   
        }
    }

    if ( is_array( $nettmagasintags ) ) {
            foreach ( $nettmagasintags as $nettmagasintag ) {

                    echo '<li><a href="' . get_term_link( $nettmagasintag->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $nettmagasintag->name ) . '" ' . '>' . $nettmagasintag->name.'</a></li> ';  
        }
    }
}

The above code then adds edwien category and a tag, and then the nettmagasin category and tag. I am still working on a few things around these custom post types and will also be producing a tutorial. I will then later on either edit this post or add another with a link to a tutorial.

Write a reply

Login or register to write a reply, it's free!