1

I have created a Custom Post Type called Program

I want logged in users to get associated with a program:

  1. User goes to Program page
  2. User clicks on Register button
  3. User fills details in the form and pushes Submit button.

Afterwards I should be able to create a report which lists:

  1. All the users who are associated with any Program
  2. List of users who are associated with a selected program & role

How should I do that?

0

You have to create a custom taxonomy:

add_action( 'init', function(){
    register_taxonomy( 'program', 'your_post_type', array() );
});

To get users associated with a program, get all posts that have your desired program term:

$query = new WP_Query( array(
    'post_type' => 'your_post_type',
    'tax_query' => array(
        array(
            'taxonomy' => 'program',
            'field'    => 'name',
            'terms'    => 'your_program_name',
        ),
    ),
) );

Now get all the result posts authors and that would give you the users associated to that specific program.

$posts = $query->posts;

foreach($posts as $post) {
    $author = $post->post_author;
}
| improve this answer | |
  • As far as my understanding, custom taxonomy are used for categorizes the custom post type i.e.Program but my requirement is when a logged-in user click on register program link/button of a post (CPT) i.e. Program, User Detail is collected in Database which we retrieve to get the total count of user registered for the selected program. – Khirat Hussain Mar 24 at 13:43
  • The user will create one of your CPT which will make him the author. That's already a link you can use without further complicating things, if you want to add context to that link between a CPT 'program' and it's author, then you use a taxonomy term, ex: 'Chrome'. – Himad Mar 24 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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