0

I have 2 forms. Form A creates a new user with the role of Author and also creates an entry in a CPT called Judges.

Form B creates a new user also with the role of Author and creates an entry in a CPT called Submissions.

So if both forms are submitted we have 2 new users both with the same role of Author, one has created a Judge entry, the other a Submissions entry.

On author.php I need to show the personal info like name, email etc. Now, I also need to display those forms again and query some other CPT info. The problem is, how can I show Author A the judge form and only content related to CPT judges, and Author B the Submissions form and only content related to CPT Submissions.

Ive been trying to use something like this as a start.

<?php if( get_post_type() == 'judges' ) { //start CPT conditional ?>

<?php } elseif ( get_post_type() == 'submissions' ) { ?>

<?php } //end CPT conditional ?>
1
  • Can you more precise about your conditional checks? get_post_type() would require an ID in your case (I think). Do you supply that? Commented Oct 4, 2015 at 7:54

1 Answer 1

0

Based on the description of your issue it sounds like there is one key piece of information missing. When the form is submitted you need to insert a custom meta value in wp_usermeta that will create a relationship between the new user and the corresponding custom post type. Lets call it meta_key = 'user_post_id' for the code example below.

This custom meta value can then be used on your author.php page to handle the split logic you mentioned above:

<?php
// get the 'user_post_id' from the 'wp_usermeta' table
$post_id = get_user_meta($user_id, 'user_post_id', true);

// start the split logic
if( get_post_type($post_id) == 'judges' ) { /* judges code goes here */ }
elseif( get_post_type() == 'submissions' ) { /* submissions code goes here */ }
?>

As an alternative to creating a relationship to a specific post, you could just set a 'user_type' meta key with a value of either 'judges' or 'submissions'. In that case the code would adjust as so:

<?php
// get the 'user_type' from the 'wp_usermeta' table
$user_type = get_user_meta($user_id, 'user_type', true);

// start the split logic
if( $user_type == 'judges' ) { /* judges code goes here */ }
elseif( $user_type == 'submissions' ) { /* submissions code goes here */ }
?>
1
  • Thanks for that. I am using Gravity forms which has an ID stored as post metadata for each entry so was able to use that along with your code. Commented Oct 5, 2015 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.