Help displaying custom image fields
-
I have had no trouble displaying custom text fields using the shortcode method but when I attempt to do this with an image field it spits out an id number.
This is the code I’m using.
add_filter( 'display_posts_shortcode_output', 'be_display_posts_custom_fields', 10, 6 ); function be_display_posts_custom_fields( $output, $atts, $image, $title, $date, $excerpt ) { // Get our custom fields global $post; $solutionimage = get_post_meta( $post->ID, 'solution_image', true ) ; $test = get_post_meta( $post->ID, 'test', true ) ; // If there's a value for the custom field, let's wrap them with <span>'s so you can control them with CSS if( isset( $solutionimage ) ) $solutionimage = '<span class="solution-image">' . $solutionimage . '</span> '; if( isset( $test ) ) $test = '<span class="test">' . $test . '</span> '; //if( isset( $atts['solution_image'] ) && "true" == $atts['solution_image'] ) //echo $solution_image; // Now let's rebuild the output. $output = '<li class="solution__entry">' . $test . $image . $title . $solutionimage . $date . $excerpt . '</li>'; // Finally we'll return the modified output return $output; }[display-posts post_type="solution" solution_image="true" wrapper_class="solution-entries"]
The topic ‘Help displaying custom image fields’ is closed to new replies.