Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm working for a WordPress Plugin. The plugins is for library management, for my university. I created custom post types with taxonomies for keeping books information stored. Now I want to create another post type which will keep records for books and and users. For instance, I'll create new post type called "Issue". There should have three fields. One would be title. Another two will be dropdown, one will show all book (I've already created custom post type called books, I want to use those here, automatically) lists as dropdown. Another dropdown field will show list of students (for this I've created a new user role called student, I want to use those user who are registered as student).

So my questions are

  1. How can I show all users (selected role) as dropdown in custom meta box and
  2. How can I show all books (Custom post type I created) as dropdown in custom meta box

How can these be done? I can code, need instruction ;)

share|improve this question
2  
Can you separate things out a little more so it isn't a single giant paragraph? Use bullet points for extra points –  Tom J Nowell Apr 16 '12 at 15:45
    
Thanks for your suggestion :) I'll do from next. –  Enthusiast Apr 16 '12 at 15:52
1  
This sounds like several questions in one, as I think will become evident, once you implement @TomJNowell's suggestion. –  Chip Bennett Apr 16 '12 at 16:01
    
Chip, just tried to do :) –  Enthusiast Apr 16 '12 at 17:07
add comment

2 Answers

up vote 4 down vote accepted
  • To get the users who have the role called student, use the WP_User_Query object
  • For storing the fields, use post meta just as you would on normal posts, remember to declare that your custom post type supports custom fields when being registered
  • For your dropdown/etc you will need to register metaboxes

More info on WP_User_Query.

For how to add metaboxes see the Codex entry and examples for this function.

share|improve this answer
    
Thanks Tom. Now need idea how to get custom post type list as dropdown :) –  Enthusiast Apr 16 '12 at 15:54
    
Just use WP_Query like you would on the frontend, there are plenty of questions on this site asking how to grab custom post types, I advise you use the searchbox! –  Tom J Nowell Apr 16 '12 at 16:16
    
I know customizing loop, custom post type can be displayed, but have no idea how to use than in a meta box. Anyway, I'll try now definitely. Thanks a lot Tom. –  Enthusiast Apr 16 '12 at 17:01
add comment

Here is the code I used to create a dropdown of my Custom Post Type "Issues" to display the title of the "Issue" and have the value link to the single issue.

  <label>Published In:</label>

  <p><select name="issue-date">
  <?php 
  $args = array( 'post_type' => 'issues');
  $loop = new WP_Query( $args );
  while ( $loop->have_posts() ) : $loop->the_post();

  echo '<option value="';
  the_permalink();
  echo '">';
  the_title();
  echo '</option>';
  endwhile;
  ?>

  </p>

Hope it helps someone.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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