• Resolved rocketmediauk

    (@rocketmediauk)


    Hi,

    I am using pods in conjunction with WP WordPress Manager. I have a POD setup with a relationship field that links to a WP Download Manager Post.

    I now want to display a download link for the WP download Manager post (I am creating a POD template to do this), which usually I would do this with: echo do_shortcode(“[wpdm_package id=’???’ template=’link-template-button’]”)

    The ID of the WP Dwonload Post I can get with magic link {@resource_link_protected.ID}, but I am struggling to use it to display the shortcode

    I have tried

    echo do_shortcode(“[wpdm_package id='{@resource_link_protected.ID}’ template=’link-template-button’]”)

    and

    $protected_id = ‘{@resource_link_protected.ID}’;
    echo do_shortcode(“[wpdm_package id=’$protected_id’ template=’link-template-button’]”)

    If I do
    $protected_id = ‘1554’;
    echo do_shortcode(“[wpdm_package id=’$protected_id’ template=’link-template-button’]”)

    Then I get the download link, So I am struggling getting {@resource_link_protected.ID} into a variable or use in a shortcode

    Any Ideas?

Viewing 15 replies - 1 through 15 (of 34 total)
  • Thread Starter rocketmediauk

    (@rocketmediauk)

    This is within a POD template

    Thread Starter rocketmediauk

    (@rocketmediauk)

    Can i set a magic tag as a variable so it can be used in various PHP uses? That’s what I am struggling with, saving a magic tag as a variable so I can use it in a if statement for example.

    Thread Starter rocketmediauk

    (@rocketmediauk)

    Anyone?

    Thread Starter rocketmediauk

    (@rocketmediauk)

    Is this the best way to get support or is this plugin just not very well supported?

    Plugin Support Paul Clark

    (@pdclark)

    Get the ID with get_post_meta() or Pods ->field().

    Thread Starter rocketmediauk

    (@rocketmediauk)

    Hi Paul,

    How do I get the ID when I am in a template for ‘Single Pods Item’ block? The info on your page says $books = pods( ‘books’, 123 ); but I can’t get the ID of the selected POD to use instead of 123 as I can’t set magic tags as variables.

    With get_post_meta, that will give me the meta for the page I am displaying the blocks on, but again I need the POD ID to be able to get useful information, which I am unable to do.

    Or am I missing something?

    I assume from your answer there is noway to set a magic tag as a variable? Such as $test = {@resource_link_protected.ID}. Because these doesn’t work for PHP If statements for example.

    Plugin Support Paul Clark

    (@pdclark)

    There is do_magic_tags(): https://docs.pods.io/code/pods/do-magic-tags/ but it will likely be simplest to define a custom shortcode, or pass the ID from the magic tag to a custom function by appending a comma and the function name:

    In template: {@resource_link_protected.ID,do_wpdm}
    
    In theme functions.php or a plugin file:
    <?php
    function do_wpdm( $id ){
        return do_shortcode( "[wpdm_package id='$id' template='link-template-button']" );
    }
    Thread Starter rocketmediauk

    (@rocketmediauk)

    Thanks that works for the shortcode but I still need to save it as a variable which doesn’t seem to work

    This is what I have:

    In Function:

    function do_getid( $id ){
       return $id;
    }

    In File

    $test = '{@resource_link_protected, do_getid}';
    print_r($test); 
    //This shows the correct title which is Actions for Coaches Guide
    
    while ( $wpdm_loop->have_posts() ) :  $wpdm_loop->the_post();
       print_r(get_the_title());  
       //This show the titles in my loop, one of which is Actions for Coaches Guide
          if( get_the_title() == $test ){
             echo 'IT WORKS!'; //This doesn't display   
          }
    }

    So setting the variable to a magic tag for some reason doesn’t work because if I was to manually change $test to $test = ‘Actions for Coaches Guide’; it does work

    Plugin Support Paul Clark

    (@pdclark)

    Magic tags are pre-parsed by PHP, so assignment can’t work that way. To save the value of a magic tag to a variable in PHP, use do_magic_tags().

    Thread Starter rocketmediauk

    (@rocketmediauk)

    Hi Paul,

    Can you give me an example? There isn’t a lot of info on that page

    Plugin Support Paul Clark

    (@pdclark)

    $id = do_magic_tags( '{@resource_link_protected.ID}' );
    Thread Starter rocketmediauk

    (@rocketmediauk)

    I get an error:
    Uncaught Error: Call to undefined function do_magic_tags()

    Thread Starter rocketmediauk

    (@rocketmediauk)

    Ohh I put the function in functions.php and getting some return. I will test this

    function do_magic_tags( $code ){
    return $code;
    }
    Thread Starter rocketmediauk

    (@rocketmediauk)

    Ok so I am still having issues using in some PHP such as the If statement I put earlier. This is what I put:

    $podtitle =do_magic_tags('{@resource_link_protected}');
    while ( $wpdm_loop->have_posts() ) : $wpdm_loop->the_post();	
       if( get_the_title() == $podtitle){		
          echo 'IT WORKS';	
       }
    endwhile;

    I wonder if the problem exists in the encoding of the magic tages as when I var_dump $podtitle the string displays as it should but has a length of 51 while as the_title has a length of 37 even though they have the same string, so maybe some hidden characters are there?

    Plugin Support Paul Clark

    (@pdclark)

    Sorry, no, it’s a method of the pods class, not a function. My mistake. You shouldn’t need to define it.

    Try this:

    $pod = pods( get_post_type(), get_the_ID() );
    $pdmid = $pod->field( 'resource_link_protected' ); // may or may not require “.ID”
    $pdmid_mt = $pod->do_magic_tags( '{@resource_link_protected.ID}' );
Viewing 15 replies - 1 through 15 (of 34 total)
  • The topic ‘Third Party Shortcode and POD value’ is closed to new replies.