Home Forums General Issues Custom widget to different posts


Custom widget to different posts

  • Hello
    I wanted to create a custom widget for every post.

    So I add to the function.php this code

    add_filter( 'widget_text', 'do_shortcode' );
    add_shortcode( 'mytext', 'so_13735174_custom_text_widget' );
    function so_13735174_custom_text_widget( $atts, $content = null )
        global $post;
        // $post contains lots of info
        // Using $post->ID many more can be retrieved
        // Here, we are getting the Custom Field named "text"
        $html = get_post_meta( $post->ID, 'text', true );
        // Custom Field not set or empty, print nothing
        if( !isset( $html ) || '' == $html )
            return '';
        // Print Custom Field
        return $html;

    And then add text widget with shortcode [mytext]

    Everything work perfect, but I wanted to add Filed Type:”Relationship” to show posts with thumbnail on different posts and pages.

    But it only displays “Array”.

    I am not a programer and any help will be appreciate it.

Viewing 1 post (of 1 total)

The topic ‘Custom widget to different posts’ is closed to new replies.