Hi there,
I assume you’re adding this into your Give single form page template via a child theme. If so, you just need to add meta key values into the query args. Here’s a functioning example:
// Query 1 Argument
global $post;
$args = array(
'post_type' => 'give_payment',
'posts_per_page' => 3,
'meta_key' => '_give_payment_form_id',
'meta_value' => get_the_ID()
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) : ?>
<h2>Output latest 3 donations with amount and date</h2>
<hr/>
<ul>
<?php
while ( $loop->have_posts() ) : $loop->the_post();
$meta = get_post_meta( get_the_ID() );
$title = $meta['_give_payment_form_title'][0];
$total = $meta['_give_payment_total'][0];
$getdate = $meta['_give_completed_date'][0];
$date = date( "F j, Y", strtotime( $getdate ) );
$gateway = $meta['_give_payment_gateway'][0];
?>
<li><strong>Donation for $<?php echo $total; ?></strong><br/>
Was given on <?php echo $date; ?><br/>
Through the <?php echo $title; ?> form.
</li>
<?php endwhile;
wp_reset_postdata(); // end of Query 1 ?>
</ul>
<?php else : ?>
<!-- If you don't have donations that fit this query -->
<h2>Sorry you don't have any transactions that fit this query</h2>
<?php endif;
wp_reset_query();
This is based off our Snippet in our Snippet Library:
https://github.com/WordImpress/Give-Snippet-Library/blob/master/useful-queries/sample-transaction-queries.php
Let me know how that goes. Thanks!
Thread Starter
ouze
(@absico)
Thank you Matt
I using it with give.php added under the root of my theme.
Now, when I use your example it shows the else result “Sorry you don’t have any transactions that fit this query”.
Can you paste the whole file into a Gist for me to test fully?
Thread Starter
ouze
(@absico)
hmm… it worked as expected for me. Are you sure you have donations that were made with the form you are testing it on?
Are you using Give’s single page urls, or inserting the form on a page via the shortcode? If via the shortcode then it won’t work as expected since it’s looking for the payment meta ID to be the same as the current post ID.
Thread Starter
ouze
(@absico)
yes I have donation for the form I am testing and I am not using shortcodes.
I did not add your example to the page I sent you . I just sent you my page before modification.
This is the page after adding the meta key value.
would you please try it
https://gist.github.com/anonymous/014f0cf7145a43b22c3a5f3f17a16945
Do you have this live so I can see the output? If so, add this to line 146:
var_dump($getmeta);
That will tell us what is being output from the give_payments CPT.
Thread Starter
ouze
(@absico)
I don’t see the var_dump($getmeta); outputting there. Did you try that? Did it output anything for you? That’s the data I need to understand what’s going on.
Thread Starter
ouze
(@absico)
first I would like to thank you for your patience and support
It is not displaying any thing when added to line 146 because it is under the first condition which is not displayed .Am I right ?.I added it to line 166 inside the else statement and it show null. you can check it online now.
http://mosaicinitiative.org.uk/wptest/donations/campaign-3/
Hmmm… I see you’re also using Recurring Donations. Can you contact us via our Priority Support form? I can help you much better there:
https://givewp.com/support
Please reference this ticket in your request and mention me so I’ll get assigned directly. Thank you!