The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Variables in shortcodes (2 posts)

  1. waynmeyer
    Posted 2 years ago #

    Hi Gabriel

    i have a noob question. im using Advanced custom fields and custom post types as well as custom template types. However im stuck where i need to echo an advanced custom field in the shortcode of mycred. example:

    <?php $variable = the_field('youtube_video_id');
    echo do_shortcode('[mycred_video id="'.$variable.'" width="800" height="" amount="5" logic="interval" interval="15"]'); ?>

    say in the above im using the youtube video mycred shortcode. to show the view i want to echo an advanced custom field for the video id, this was i can have users make posts using their videos custom id without them having to learn mycred shortcodes, they simply add just the video id which i can echo in your shortcode.

    Is there anyway i can use mycred with php and not have to use the echo do_shortcode method?

    Any assistance will be greatly appreciated


  2. Gabriel
    Plugin Author

    Posted 2 years ago #


    You can use the mycred_render_shortcode_video function which is the function that renders the shortcode and the video javascript files which contains the AJAX script that updates a users balance.

    Here is a quick example:

    // Show the video via myCRED if a YouTube Video is set
    $video_id = the_field( 'youtube_video_id' );
    if ( $video_id != '' && function_exists( 'mycred_render_shortcode_video' ) ) {
    	echo mycred_render_shortcode_video( array(
    		'id'       => $video_id,
    		'width'    => 560,
    		'height'   => 315
    	) );

    The shortcode attributes are passed along as an array. The above example is equalant to:

    $video_id = the_field( 'youtube_video_id' );
    if ( $video_id != '' ) {
    	echo do_shortcode( '[mycred_video id="' . $video_id . '" width="560" height="315"]' );

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • myCRED
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic