Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Custom widget to different posts

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #183223
    kaioian
    Participant

    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. Thanks.

Viewing 1 post (of 1 total)
  • The forum ‘Back End’ is closed to new topics and replies.