[Support request] Custom field values as dynamic values in shortcodes

Home Forums Support [Support request] Custom field values as dynamic values in shortcodes

Home Forums Support Custom field values as dynamic values in shortcodes

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2351297
    vast

    The post How to use custom field values as dynamic data in shortcodes and HTML works great if the output is a string. The example from Elvin works excellently. Is there a similar approach for objects such as files i.e. it outputs a title of the file and a link to download it for a given post or a list of titles and links if there’s more than one file?

    add_shortcode('display_custom_field', function ($atts){
    	ob_start();
    	
            $atts = shortcode_atts( array(
                'field_name' => 'no foo'
            ), $atts, 'display_custom_field' );
    
    	$customfield = get_post_meta( get_the_ID(), $atts['field_name'] , true );
    	if( $customfield ){ 
    		$output = $customfield;
    	} 
    	echo $output;
    	return ob_get_clean();
    });
    #2351308
    Fernando
    Customer Support

    Hi vast,

    What plugin are you using to generate the Custom fields?

    #2351940
    vast

    Advanced Custom Fields – https://www.advancedcustomfields.com/

    #2351965
    Ying
    Staff
    Customer Support

    Hi there,

    It’s better to reach out to the ACF plugin for further instructions.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.