• Hi,
    I’m trying to figure out how to integrate register post type with my plugin. What I need is that each author have access to post to his/her course. So I need a drop down menu that would select the course he wants to post to. Thanks in advance.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator bcworkz

    (@bcworkz)

    What differentiates one course from another? Post type? Category? Custom taxonomy? Custom field? Metadata? Author? MU Blog?

    Where should this dropdown appear?

    Thread Starter jnwry

    (@jnwry)

    I’ve set up WP for lessons.
    So I’m using “register_post_type”, to enter lessons. What I need is below the typical WP text entry, a few added fields like a drop down and a few others.
    Hope this makes sense. I apologize for my ignorance on this.

    Moderator bcworkz

    (@bcworkz)

    No need for apologies, I too was ignorant of WP not that long ago.

    If you have a unique post type for each lesson or course (same thing? or no?), you could control access through the built in capabilities. Then only lessons/post types for which an author has capabilities will show up in his menu. As each post type is listed in the admin menu separately, do you really need a drop down? Or are things altered such that this behavior is not happening?

    When you say this dropdown should be below typical text entry, I take it you mean the post edit screen? In such cases, the fields are contained in a metabox which is added to the edit screen with add_meta_box(). The thing is though, by the time this screen is displayed, the post type is already selected from the admin menu, so logically it is too late to be selecting a post type.

    It does appear you could force the edit screen to submit for a different post type than what is intended by using javascript to change the value of the hidden field named ‘post_type’. I’ve not tested this though, and IMO it does not make sense to change post types here, why not pick it from the admin menu?

    I feel like I’m missing something. I’ll try to help you do what ever you want, but it helps me if I understand what’s going on. Right now I’m a little confused.

    Thread Starter jnwry

    (@jnwry)

    unique post type for each course. This would come from the admin menu. Once course is selected, you create lessons (posts) with X multiple choice questions attached to each lesson. Hope this helps…

    Moderator bcworkz

    (@bcworkz)

    Ok, that’s what I thought, except for lessons as posts. Thanks for clarifying.

    The way custom post types work, I don’t see the need to do anything special. Each teacher/author’s courses/post_types show up in the admin menu and they can add lessons/posts under each course using the Add New pick.

    That is my opinion of course. If you think it’s important to have a drop down somewhere, I’ll still try to help you do it. I’m still unclear where this would go. Putting it on the post edit screen does not make sense to me because I (as a user) already selected which course to add to when I decided which course/post_type’s “Add New” to use. And those picks are always available on the menu if I should change my mind.

    FWIW, if I were to place such a dropdown somewhere, (even though it’s not needed) I think I would try to add it as a dashboard widget. Picking from it would immediately open the associated new lesson/post screen for that course/post_type.

    Thank you for you patience. I may need to try it even more I’m afraid. I’m going to have spotty Internet access soon for about a week. It may sometimes be a few days before I can reply to new posts, but I promise I will not forget about you.

    Thread Starter jnwry

    (@jnwry)

    Hi bcworkz,

    Here is my first bit of code. It lists the courses the user currently has listed to his name:

    $queries = $wpdb->get_results("SELECT courseid, course FROM ".$wpdb->prefix."vcos_courses WHERE ownerid='$userid'");
    		foreach ($queries as $query){
    
    		$course = $query->course;
    		$args = array(
    			'public' => true,
    			'label' => $course
    			);
    
    			register_post_type( $course, $args );
    
    		}

    Now, what I have clarified in my mind to do (and after much investigating), is to add an option to add multiple choice questions below the posting of the text. So, the user can just keep adding as many questions as I they need. Obviously all the questions need to be assigned to the course->lesson….NO idea how to go about this….

    Moderator bcworkz

    (@bcworkz)

    Maybe if I generalize my answer instead of trying to understand where you’re going with this, you’ll have enough information to work out the details on your own. (Always willing to help if need be though).

    Regardless of the purpose, you want to know how to add more form fields to the Post Edit screen. This done with either custom fields, which are available by default (you may need to enable the widget in your screen options), or by adding metaboxes.

    The custom fields are rather limited, you can only add text boxes. With metaboxes, you can add almost any HTML and form elements you like. Radio selects, dropdowns, checkboxes, text areas, etc. More coding is required, but the possibilities are almost endless, especially if AJAX techniques are employed for optimal user interaction.

    If you want to add post type selections here despite my objections, metaboxes will let you do it. You can add test question and answer fields this way as well. With AJAX techniques, you could allow the user to add as many question fields as needed.

    The other side of the equation is displaying the questions and answers to the users. Since you code where this data is stored, you will need a single post template to grab this data and present it with the appropriate radio buttons. You would need more code to accept the student form submits and do something with the data. Assuming this is what you had in mind, I took what you said about multiple choice and ran with it.

    That’s all further down the line, right now, just focus on adding a simple metabox that successfully saves data and add a template tag to the single post template to display this data. Once you’ve figured that process out, it just a matter of building on that with more complex information.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘add drop down menu to register post type’ is closed to new replies.