Skip to content

Instantly share code, notes, and snippets.

@obiPlabon
Last active July 14, 2018 21:37
Show Gist options
  • Save obiPlabon/13be265a5f267ca68e8a to your computer and use it in GitHub Desktop.
Save obiPlabon/13be265a5f267ca68e8a to your computer and use it in GitHub Desktop.
function list_wpcf7_form_shortcodes() {
global $post;
if ( ! post_type_exists( 'wpcf7_contact_form' ) )
_e( "You haven't install/activate Contact Form 7 plugin yet.", "text_domain" );
$wpcf7_posts = get_posts( array(
'post_type' => 'wpcf7_contact_form',
'posts_per_page' => -1,
) );
echo "<select name='wpcf7_shortcodes'>";
foreach ( $wpcf7_posts as $post ) : setup_postdata( $post );
$wpcf7_shortcode = '[contact-form-7 id="' . get_the_ID() . '" title="' . get_the_title() . '"]';
echo "<option value='" . $wpcf7_shortcode . "'>" . $wpcf7_shortcode . "</option>";
endforeach;
wp_reset_postdata();
echo "</select>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment