Home Forums Front-end Issues Show single custom post with Shortcode


Show single custom post with Shortcode

  • Hi there

    I have tried to call a single custom post with this shortcode:

    function cpt_content_func($atts){
    $post = ”;
    $content = ”;
    extract( shortcode_atts( array(
    ‘slug’ => null,
    ), $atts ) );

    $args = array(
    ‘name’ => $slug,
    ‘post_type’ => ‘rejser’,
    ‘numberposts’ => 1
    $post = get_posts( $args );

    if ( !empty( $post ) ) {
    $content = apply_filters( ‘the_content’, get_post_field( ‘post_content’, $post[0]->ID ) );

    return $content;
    return ob_get_clean();

    It retrieves the information from the original wysiwyg-field, every posts have.
    It does not show the fields i have made with ACF.

    I tried to include this line:


    Still no effect..

    Do you know how to make the shortcode show all the custom fields? Is there a function to do just that, or maybe a plug-in, if my shortcode function is not possible to work with.

    Thank you in advance!

    Best Regards

  • Can you post your code where the shortcode involved is called as well as the complete code of your function? Please use the code button at the top of the editor to enclose your code so that it can be read more easily.

    Your code should look like this

       // your code here
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Show single custom post with Shortcode’ is closed to new replies.