I have created a Custom Post Type called Program
I want logged in users to get associated with a program:
- User goes to Program page
- User clicks on Register button
- User fills details in the form and pushes Submit button.
Afterwards I should be able to create a report which lists:
- All the users who are associated with any Program
- List of users who are associated with a selected program & role
How should I do that?
I have created a Custom Post Type called Program
I want logged in users to get associated with a program:
- User goes to Program page
- User clicks on Register button
- User fills details in the form and pushes Submit button.
Afterwards I should be able to create a report which lists:
- All the users who are associated with any Program
- List of users who are associated with a selected program & role
How should I do that?
Share Improve this question edited Mar 24, 2020 at 0:05 WordPress Speed 2,2833 gold badges19 silver badges34 bronze badges asked Mar 22, 2020 at 8:34 Khirat HussainKhirat Hussain 111 bronze badge1 Answer
Reset to default 0You 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;
}