Template variables

In the wdf_confirm.php template, I need to pick up the contribution level (how much was pledged or donated) and the pledge ID. How do I include those in the page template?

I actually need them added to a form generated by Contact Form 7, so if there is a more direct way, all the better. My tactic is otherwise to get these two values and add input elements with javascript to the form.

  • Cole
    • The Incredible Code Injector

    Take a look at template-functions.php in the plugin folder.

    function wdf_amount_raised($echo = true, $post_id = '') {
    	global $post, $wdf;
    	$post_id = (empty($post_id) ? $post->ID : $post_id );
    	if(!get_post($post_id))
    		return false;
    	$raised = $wdf->format_currency('',$wdf->get_amount_raised($post_id));
    
    	if($echo) {echo $raised;} else {return $raised;}
    
    }

    And your also trying to get out each pledge ID associated with a single fundraisier???

    global $wdf;
    $all_pledges = $wdf->get_pledge_list($fundraiser_post_id);

    $all_pledges will be a standard wp get_posts() return of each pledge post object. So you could access the pledges' ID by doing the following.

    if($all_pledges) {
        foreach($all_pledges as $pledge) {
            echo $pledge->ID;
        }
    }
  • calle
    • Flash Drive

    @Patrick, well, getting the $wdf object helped, but for another issue. I made a shortcode to output fundraiser data.

    For the pledge ID, I am currently getting the GET variable instead, since I haven't gone into depth on the actual $wdf object. Getting all_pledges and parsing that seems overkill to me, since the pledge_id is in the URL on the confirmation page already. It would be much simpler with a get_pledge or get_pledge_id function that returns the pledge or pledge ID, respectively, or false if you're not on a page where a specific pledge can be retrieved.

    I can see a scenario where a person would want to regret the pledge, and allowing specific url for that (sent in the donation email), the get_pledge function would be beneficial. I have to admit that I haven't had time to check for the availability of that, or a similar function, I'll just rely on your feedback for that.

  • Cole
    • The Incredible Code Injector

    Hey calle,

    I didn't make an internal function for this but you can use a function out of the WP core. The name of it is a bit deceiving but this will do the trick. The pledge_id is actually stored in the post_title so we can use get_page_by_title().

    http://codex.wordpress.org/Function_Reference/get_page_by_title
    $pledge = get_page_by_title( $pledge_id, null, 'donation' )

    You can replace the null variable with your preferred type of output OBJECT, ARRAY_N, or ARRAY_A. Default is an OBJECT so you would access the variables using ->
    $pledge->ID

    Let me know how that works.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.