• Resolved nimmalareddy

    (@nimmalareddy)


    Am using a DATE field for a custom post type (events) (both created via your plugin).
    Am trying to display a list of events with custom field displayed as well, using “display posts plugin“.
    Am using the following code as guided by the plugin author here

    function be_dps_include_event_date( $output, $original_atts, $image, $title, $date, $excerpt, $inner_wrapper, $content, $class, $author, $category_display_text ) {
    	if( empty( $original_atts['include_event_date'] ) || false === filter_var( $original_atts['include_event_date'], FILTER_VALIDATE_BOOLEAN ) )
    		return $output;
    	$key = 'field_3d0p5'; //this is the field from your plugin.
    	$event_date = get_post_meta( get_the_ID(), $key, true );
    	if( empty( $event_date ) )
    		return $output;
    	// Convert to formatted date.
    	// See: https://www.ads-software.com/support/article/formatting-date-and-time
    	$event_date = date( 'F j, Y', $event_date );
    	// Add span around it for styling
    	$event_date = '<span class="event-date">' . $event_date . '</span>';
    	// Insert it into the output wherever you'd like it
    	$output = '<' . $inner_wrapper . ' class="' . implode( ' ', $class ) . '">' . $image . $title . $event_date . $date . $author . $category_display_text . $excerpt . $content . '</' . $inner_wrapper . '>';
    	return $output;
    }
    add_filter( 'display_posts_shortcode_output', 'be_dps_include_event_date', 10, 11 );

    But out put is not showing the custom field. What am i doing wrong? Is the key wrong?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Andrea De Giovine

    (@andreadegiovine)

    Hello developer ??
    At the moment the plugin stores all post fields in a single metakey.
    To return the value of a field you can use this function (in the description of the plugin):

    get_custom_field($field_id, $post_id)

    and therefore in your function:

    $event_date = get_custom_field( 'field_3d0p5' , get_the_ID() );

    let me know if it works and if you need other functions or hooks (filter, actions) in the plugin.

    TOP SECRET ( don’t tell anyone ?? ):
    I’m working on an update to move the fields each into a single metakey, including a converter for everyone who already uses the plugin so no one loses data. After this update it will be possible to perform any metaquery using the IDs of the custom fields.

    Thread Starter nimmalareddy

    (@nimmalareddy)

    Lol..
    I’ll wait till the next secret update instead of testing now ??
    Please release Hooks and filters list on your website along with certain usage scenarios for noobs like me ??
    Thanks for the amazing work.

    • This reply was modified 5 years, 3 months ago by nimmalareddy. Reason: For hooks
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom fields on Qeury’ is closed to new replies.