Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
The building blocks for using Gravity Forms to build an online petition
<?php
// ADDING CUSTOM POST TYPE
add_action('init', 'all_custom_post_types');
function all_custom_post_types() {
$types = array(
// Pledge Items
array('the_type' => 'pledge',
'single' => 'Pledge',
'plural' => 'Pledges'));
foreach ($types as $type) {
$the_type = $type['the_type'];
$single = $type['single'];
$plural = $type['plural'];
$labels = array(
'name' => _x($plural, 'post type general name'),
'singular_name' => _x($single, 'post type singular name'),
'add_new' => _x('Add New', $single),
'add_new_item' => __('Add New '. $single),
'edit_item' => __('Edit '.$single),
'new_item' => __('New '.$single),
'view_item' => __('View '.$single),
'search_items' => __('Search '.$plural),
'not_found' => __('No '.$plural.' found'),
'not_found_in_trash' => __('No '.$plural.' found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 5,
'supports' => array('title','editor','thumbnail','custom-fields','excerpt'));
register_post_type($the_type, $args);
}
}
?>
<?php
<div class="block">
<ol reversed="reversed" class="pledge-item">
<?php
$args = array( 'post_type' => 'pledge', 'posts_per_page' => 100 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
/* with sprintf() you make a “pattern" first using %s and some other possible symbols then you define them with php functions/variables */
printf( '<li>%s,&amp;nbsp;%s,&amp;nbsp;%s,&amp;nbsp;%s,&amp;nbsp;%s</li>',
get_the_title(),
get_post_meta($post->ID, 'age', true),
get_post_meta($post->ID, 'city', true),
get_post_meta($post->ID, 'state', true),
get_post_meta($post->ID, 'country', true)
);
endwhile;
?>
</ol>
</div>
<!–end block–>
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment