Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(snippet-library): add snippet to output list of closed forms. #78 #79

Merged
merged 1 commit into from
Aug 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 55 additions & 0 deletions custom-shortcodes/goal-achieved-form-list-shortcode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* SHORTCODE -- Goal Achieved Forms
* Example: [give_goal_achieved_forms]
*/
function give_render_goal_achieved_forms_list() {

// Arguments to only fetch forms with goal enabled.
$form_args = array(
'post_type' => 'give_forms',
'post_status' => 'publish',
'posts_per_page' => get_option( 'posts_per_page' ),
'orderby' => 'date',
'order' => 'ASC',
'meta_key' => '_give_goal_option',
'meta_value' => 'enabled',
);

// Query to output donation forms.
$form_query = new WP_Query( $form_args );

if ( $form_query->have_posts() ) {
ob_start();

printf( '<table><thead><th>Form ID</th><th>Form Name</th></thead><tbody>' );

while ( $form_query->have_posts() ) {

$form_query->the_post();

$goal_stats = give_goal_progress_stats( get_the_ID() );

// Skip printing the form if the goal is not achieved.
if ( $goal_stats['raw_actual'] < $goal_stats['raw_goal'] ) {
continue;
}

// Print Form ID and Form Title with hyperink.
printf(
'<tr><td>%1$s</td><td><a href="%2$s">%3$s</a></td></tr>',
get_the_ID(),
get_the_permalink(),
get_the_title()
);
}

printf( '</tbody></table>' );

wp_reset_postdata();

return ob_get_clean();
}
}

add_shortcode( 'give_goal_achieved_forms', 'give_render_goal_achieved_forms_list' );