WordPress.org

Forums

myCRED
Variables in shortcodes (2 posts)

  1. waynmeyer
    Member
    Posted 1 year 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

    https://wordpress.org/plugins/mycred/

  2. Gabriel
    Member
    Plugin Author

    Posted 1 year ago #

    Hi.

    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