Quantcast
Channel: WordPress.org Forums » [Contact Form 7] Support
Viewing all articles
Browse latest Browse all 49500

schwarzgrau on "[Plugin: Contact Form 7] Contact Form on author.php"

$
0
0

I managed to use contact-form 7 on my author.php. But it requires a stupid setup:
I created a custom post type called fake ( propably not the best name choice )
And then on the author.php I used the following code:

$cur_id = $curauth->ID;
$dis_name = $curauth->display_name;

$fakeposts = get_posts( array(
				'post_type' => 'fake',
				'author' => $cur_id )
				);

if (!empty($fakeposts)) : 							// If there is a fakepost show the contact-form for it
	foreach( $fakeposts as $post ) :
		setup_postdata($post);
		echo do_shortcode('[contact-form-7 id="679" title="mensch-formular"]');
	endforeach; wp_reset_postdata();

else:
	$my_fakepost = array( 							// If there isn't a fakepost create one ...
		'post_title'    => 'fakepost_' . $dis_name,
		'post_content'  => 'Fakepost für ' . $dis_name,
		'post_status'   => 'publish',
		'post_author'   => $cur_id,
		'post_type' => 'fake'
	);

	$post_id = wp_insert_post( $my_fakepost );
	$fakeposts = get_posts( array(
					'p' => $post_id,
  					'post_type' => 'fake',
 					'author' => $cur_id )
 					);
 	foreach( $fakeposts as $post ) :				// ... and show the contact form for it
		setup_postdata($post);
		echo do_shortcode('[contact-form-7 id="679" title="mensch-formular"]');
	endforeach; wp_reset_postdata();

endif;

Basically it creates a fakepost for every user and shows the form inside of its loop. So the [_post_author_email] tag will work.
Again it's a really stupid setup, but at least it works, you need no plugin and you still can update Contact Form 7.


Viewing all articles
Browse latest Browse all 49500

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>