Hi geekhero,
Thank you for sharing this link and sorry for the slow reply.
Where do I add this filter? I tried editing the custom field to match my custom field (which is “publication”) instead of location, etc, and added this code directly to the php of the main plugin and it forced it to deactivate the plugin because of a syntax error so I am obviously doing something wrong. I’m not a developer so I am not well versed in php.
Do I need to instead upload it directly to the FTP server under that plugin as an additional php file?
How do I then with the shortcode call out the custom fields to be displayed? Will they be displayed by default or do I need to do a special parameter ie category=”articles” or something of that nature?
Basically the name of my custom field is “publication” so would the correct code then be:
<?php
/**
* Add custom fields to Display Posts Shortcode
* @author Bill Erickson
* @link https://www.ads-software.com/extend/plugins/display-posts-shortcode/
* @link https://www.billerickson.net/shortcode-to-display-posts/comment-page-1/#comment-4565
*
* @param $output string, the original markup for an individual post
* @param $atts array, all the attributes passed to the shortcode
* @param $image string, the image part of the output
* @param $title string, the title part of the output
* @param $date string, the date part of the output
* @param $excerpt string, the excerpt part of the output
* @return $output string, the modified markup for an individual post
*/
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;
$publication = esc_attr( get_post_meta( $post->ID, 'publication', 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( $publication ) ) $publication = '<span class="location">' . $publication . '</span> ';
// Now let's rebuild the output.
$output = '<li>' . $image . $title . $publication . $excerpt . '</li>';
// Finally we'll return the modified output
return $output;
}
Thanks for any additional help you could give. I appreciate it!