Help Desk

abstract pos

  • Posts: 24 Topics: 9
    | Permalink

    hi im having the exact same issue as this one here https://theeventscalendar.com/support/forums/topic/no-drop-down-after-adding-register_post_type-presenters-to-events-form/?loggedout=true

    i notice no answer on the post above hopefully you can help me !!

    Posts: 24 Topics: 9
    | Permalink

    create or find an instructor is not present as you see from the picture , so no way it can be saved ? timely response would be appreciated

    Posts: 11234
    | Permalink

    Hi again, Martin.

    Are you saying that you are following along with https://theeventscalendar.com/knowledgebase/abstract-post-types/ and registering a new “Instructors” linked post type and it’s not working for you?

    If yes, please provide me your entire code snippet to implement this and I’ll see how I can assist.

    Posts: 24 Topics: 9
    | Permalink

    also please note all plugins disabled except for the events calendar and pro , and themes 2014.15.16 and 2017 tried whilst plugins disabled.
    exactly that Cliff, i followed this , i also added this i had to take out a “)” on line 45 or i had syntax error.

    hope this adds the snippet correct !

    register_post_type( 'instructors', array(
        'labels'  => array(
            'name'                    => 'Instructors',
            'singular_name'           => 'Instructor',
            'singular_name_lowercase' => 'instructor'
        ),
        'public' => true
    ));
    
    function tribe_link_instructors_to_events() {
    	tribe_register_linked_post_type( 'instructors', array(
                'singular_name'           => 'Instructor',
                'singular_name_lowercase' => 'Instructor',
                'allow_multiple'          => true,
                'allow_creation'          => true
            ) );
    }
    
    add_action( 'init', 'tribe_link_instructors_to_events' );
    
    /**
     * Modify the form for "Instructors" on the events edit screen.
     *
     * @param string $post_type The post type whose form is being modified.
     */
    function tribe_modify_the_instructors_form_on_events( $post_type ) {
    
    	// We only want the "Instructors" post type; bail if it's some other post type.
    	if ( 'instructors' !== $post_type ) {
    		return;
    	}
    
    	// Add a Table Row for the Instructor Website to show up below the Instructor Name.
    ?>
    	<tr class="linked-post">
    		<td>Instructor Website:</td>
    		<td>
    			<input type='text' tabindex="<?php tribe_events_tab_index(); ?>" name='linked_instructors[website][]' class='linked-post-website instructors-website' size='25' value='' />
    		</td>
    		</tr>
    		<tr class="linked-post">
    		
    		<td>Instructor Website 2:</td>
    		<td>
    			<input type='text' tabindex="<?php tribe_events_tab_index(); ?>" name='linked_instructors[website][]' class='linked-post-website instructors-website' size='25' value='' />
    		</td>
    	</tr>
    <?php
    }
    
    add_action( 'tribe_events_linked_post_new_form', 'tribe_modify_the_instructors_form_on_events' );
    
    /**
     * Saves the instructor information passed via an event.
     *
     * @param int|null $id ID of instructor
     * @param array $data The instructor data
     * @param string $post_type The post type
     * @param string $post_status The intended post status
     *
     * @return mixed
     */
    function tribe_save_the_instructors_form_on_events( $id, $data, $post_type, $post_status ) {
    
    	// Check to see if we're updating an already-existing instructor post.
    	if ( isset( $data['id'] ) && intval( $data['id'] ) > 0 ) {
    
    		// We're updating an existing post, but only an ID was passed; no other data.
    		// So, just return the ID. Do nothing.
    		if ( count( $data )  == 1 ) {
    			return $data['id'];
    		}
    
    		// Check out the Tribe__Events__Organizer->update() method for inspiration on how to make an "update" function.
    		return example_update_instructor( $data['id'], $data );
    	}
    
    	// Otherwise, we're not updating an existing instructor; we have to make a new instructor post.
    	
    	// Check out the Tribe__Events__Organizer->update() method for inspiration on how to make a "create" function.
    	return example_create_instructor( $data, $post_status );
    }
    • This reply was modified 11 months ago by  martin75.
    Posts: 24 Topics: 9
    | Permalink

    Hi Cliff did you manage a peak into this ? this is the one thing i really bought pro version for especially as it had a guide of how to accomplish it for a novice like myself , im literally waiting on this to publish my site. may thx in advance

    Posts: 11234
    | Permalink

    Sorry for the delayed response.

    The code you shared includes example_update_instructor(), which is an undefined function. As it says in the comments, you need to create your own version of it, and it points you to https://github.com/moderntribe/the-events-calendar/blob/4.6.5/src/Tribe/Organizer.php#L417-L486 as a reference of what example_update_instructor() should be like.

    Posts: 24 Topics: 9
    | Permalink

    so i would need to create the-events-calendar/src/Tribe/instructor.php for starters i take it cliffe?

    i would draw your attention to https://theeventscalendar.com/knowledgebase/abstract-post-types/ , especialy this piece here “Doing this before version 4.2 of The Events Calendar meant lots of extra custom coding, but since 4.2 you can add or remove event-related post types with just a few simple filters” i think this is a bit misleading i purchased the pro simply for this. at no pint have i managed to have a simple instructor box in the admin new event form that says create within the box. it now seems i need to be a doctor of .php rather than “but since 4.2 you can add or remove event-related post types with just a few simple filters” . very disapointed , i know now this will never be achieved. thanks for your time

    Posts: 24 Topics: 9
    | Permalink

    is that the end of the help here ?

    Posts: 10476 Topics: 3
    | Permalink

    Hey Martin,

    Thanks for your patience over the weekend! Now that we’re back in action here on Monday, I can confirm that Cliff and I are looking into this a little bit more deeply. We’re testing your code and will get back to you ASAP with our findings.

    In the meantime, you asked this:

    so i would need to create the-events-calendar/src/Tribe/instructor.php for starters i take it cliffe?

    I would like to confirm with you that NO, you do not need to make (and should NOT make) such a file.

    You should indeed be able to create a useful “Linked Post” with our abstract post types system; if it’s failing, then there could be a bug here. We are testing and will get back to you ASAP.

    Stay tuned! 😀

    — George

    Posts: 24 Topics: 9
    | Permalink

    thank you for the update George very much appreciated.

    Posts: 10476 Topics: 3
    | Permalink

    Hey @martin75, here are several notes on this issue after some tinkering on my end:

    • First of all, you are right about a syntax error in this Gist of example code I created a while back. I have edited the Gist so that it no longer has that syntax error. Sorry about that!
    • Next, a problem I noticed in your code is that you had two separate “website” fields per instructor: “Website”, and then “Website 2”. But in your code, they were using the same field name.
      • For example, the field name for “Website” in your code is linked_instructors[website][]
      • But the field name for “Website 2” in your code is also just linked_instructors[website][]
      • The field name for “Website 2” in your code is should be unique, so something like linked_instructors[website_2][] would work better
    • As an example, here’s a modified version of my example code that shows how to have your “Website” And “Website 2” fields working with the “Create or Find” dropdown → https://git.io/vF5v7

    So I would recommend replacing your existing tribe_modify_the_instructors_form_on_events() and tribe_save_the_instructors_form_on_events() functions with the ones in that new Gist I linked above.

    Let us know if that helps at least get the “Create or Find” dropdown working!

    As cliff noted, the “create” and “save” functions themselves are ones you’ll have to create, but I can offer some insight on that once we confirm the “Create or Find” dropdown is working for the Instructors linked post type…

    …let us know what you find!

    — George

    Posts: 24 Topics: 9
    | Permalink

    Many many thanks george i really do appreciate your time and help , i have entered the foloowing into my functions file but in the instructor field there is no box atall next to instructors ive attatched screen shot , i must be missing something here!

    register_post_type( 'instructors', array(
        'labels'  => array(
            'name'                    => 'Instructors',
            'singular_name'           => 'Instructor',
            'singular_name_lowercase' => 'instructor'
        ),
        'public' => true
    ));
    
    function tribe_link_instructors_to_events() {
    	tribe_register_linked_post_type( 'instructors', array(
                'singular_name'           => 'Instructor',
                'singular_name_lowercase' => 'Instructor',
                'allow_multiple'          => true,
                'allow_creation'          => true
            ) );
    }
    
    add_action( 'init', 'tribe_link_instructors_to_events' );
    
    /**
     * Saves the instructor information passed via an event.
     *
     * @param int|null $id ID of instructor
     * @param array $data The instructor data
     * @param string $post_type The post type
     * @param string $post_status The intended post status
     *
     * @return mixed
     */
    function tribe_save_the_instructors_form_on_eventsXXX( $id, $data, $post_type, $post_status ) {
     
        // Check to see if we're updating an already-existing instructor post.
        if ( isset( $data['id'] ) && intval( $data['id'] ) > 0 ) {
     
            // We're updating an existing post, but only an ID was passed; no other data.
            // So, just return the ID. Do nothing.
            if ( count( $data )  == 1 ) {
                return $data['id'];
            }
     
            // Check out the Tribe__Events__Organizer->update() method for inspiration on how to make an "update" function.
            return example_update_instructor( $data['id'], $data );
        }
     
        // Otherwise, we're not updating an existing instructor; we have to make a new instructor post.
         
        // Check out the Tribe__Events__Organizer->update() method for inspiration on how to make a "create" function.
        return example_create_instructor( $data, $post_status );
    }
    
    /**
     * Modify the form for "Instructors" on the events edit screen.
     *
     * @param string $post_type The post type whose form is being modified.
     */
    function tribe_modify_the_instructors_form_on_events( $post_type ) {
    
    	// We only want the "Instructors" post type; bail if it's some other post type.
    	if ( 'instructors' !== $post_type ) {
    		return;
    	}
    
    	// Add a Table Row for the Instructor Website to show up below the Instructor Name.
    ?>
    	<tr class="linked-post">
    		<td>Instructor Website:</td>
    		<td>
    			<input type='text' tabindex="<?php tribe_events_tab_index(); ?>" name='linked_instructors[website][]' class='linked-post-website instructors-website' size='25' value='' />
    		</td>
    	</tr>
    
    	<tr class="linked-post">
    		<td>Instructor Website 2:</td>
    		<td>
    			<input type='text' tabindex="<?php tribe_events_tab_index(); ?>" name='linked_instructors[website_2][]' class='linked-post-website-2 instructors-website-2' size='25' value='' />
    		</td>
    	</tr>
    <?php
    }
    
    add_action( 'tribe_events_linked_post_new_form', 
    'tribe_modify_the_instructors_form_on_events' );

    also in wordpress back end the instructor field on the left in the image attatched , is not within the events on the left , should it be ?

    thankyou

    • This reply was modified 10 months, 4 weeks ago by  martin75.
    Posts: 10476 Topics: 3
    | Permalink

    Hey Martin,

    Thanks for your patience with the slow response over the Thanksgiving Holiday here in the US and such.

    In regards to your code, this is the point where things get a little bit outside the scope of the support we can provide. As Cliff noted, we cannot help with custom coding here on the forums as per the terms of our support policy which you can read here.

    However, I’m still happy to try and offer some advice about where to go from here.

    • First of all, you have some unused functions there and this is partially my fault because in the Gist I shared above, I left that function with “XXX” in its name in place…this is confusing and I apologize about that. That “XXX” function is not meant to be used, and so in fact you’ll want to do something more like this Gist here. Sorry to share another code example, but the code in the Gist I share here absolutely works for me and so I would recommend replacing your existing code with that And seeing if it helps.
    • Next, keep in mind the things Cliff noted earlier about the “example_create_instructor()” and “example_update_instructor()” functions…these don’t exist and you have to create them, using the built-in examples Cliff cited in his replies above as a guide for doing that. The code will not fully work until these functions exist and work.

    So, please try replacing your code with the code from this new Gist I made for you. Sorry about the lack of clarity in that first one!

    Let us know if this updated Gist helps to get the dropdowns working.

    Posts: 10476 Topics: 3
    | Permalink

    Hey Martin,

    Another quick note here: The dropdown is only for selecting Instructors.

    So please make sure you have existing Instructors on your site to “select from”. If you don’t, then no selection dropdown will show up, because there’s nothing to select! And so you’ll only see those creation fields…

    …just wanted to mention this. Do try the code from the updated Gist I shared with you, and then ensure that you have created some test Instructor post types, then let us know what you find!

    — George

    Posts: 24 Topics: 9
    | Permalink

    hi George many thanks for the update firstly i really appreciate it and i also fully understand about custom coding and am sure its not viable to do so!!

    i used the new gist in functions.php hers where im at . in the left pain of wp-admin i select instructor (it isn’t in the event section but stands alone) i can enter a title and then have the word press text/visual box to type whatever i like , i have no website box etc etc. regardless of this if i make 2 exaple instructors they are saved and published. if i now go to events i finally have create or select , i can select the 2 examles, but there are no other info except the name. ifi type a new name and click it i then have website boxes!! so close ey?? well if i make a test event and create a new instructor then hit publish i just get a white page and the event never gets published!! im presuming this has something to do with the example create instructor etc etc…. there isnt enough info available for me to continue this and i think its a lost cause unfortunately , such a shame . i feel with a better article it would be doable, an article start to finish with 2 demo fields functioning would be awesome for others as well as myself it has the makings of a wonderful feature!

    i really wouldn’t push on this but just for your feedback ill make a few comments for the sake of the events calendar rather than my own gain,and please don’t take the wrong way. i purchased the pro version for this feature alone (and if i don’t end up with it functioning i wont be asking for a refund as i feel the free version warrants a good donation from myself anyhow) the knowledge base article on abstract post is somewhat misleading , it also eliminates simple things that are both useful and needed, ie the very last post you made! with that included i could of been at this same stage weeks ago!!! and not wasted your time and effort!! i would suggest a rework of that knowledge base article to make it a whole lot clearer as for me its a bit more than easy with a few filters!!

    thanks again to both George and Cliff in your en devour to assist me

    Posts: 10476 Topics: 3
    | Permalink

    Hey @martin75,

    Did you try creating the example_update_instructor() and example_create_instructor() functions that Cliff mentioned earlier in this thread, using the file for reference that he mentioned?

    Thank you for your kind words and patience here.

    — George

    Posts: 24 Topics: 9
    | Permalink

    Hi george , sorry for the dealy replying , sick new born baby took prioity! ,
    here is where im at exactly.
    in my functions.php i have the following code , this is the only modification i have made.

    register_post_type( 'instructors', array(
        'labels'  => array(
            'name'                    => 'Instructors',
            'singular_name'           => 'Instructor',
            'singular_name_lowercase' => 'instructor'
        ),
        'public' => true
    ));
     
    function tribe_link_instructors_to_events() {
        tribe_register_linked_post_type( 'instructors', array(
    	    'singular_name'           => 'Instructor',
    	    'singular_name_lowercase' => 'Instructor',
    	    'allow_multiple'          => true,
    	    'allow_creation'          => true
    	) );
    }
     
    add_action( 'init', 'tribe_link_instructors_to_events' );
    
    /**
     * Modify the form for "Instructors" on the events edit screen.
     *
     * @param string $post_type The post type whose form is being modified.
     */
    function tribe_modify_the_instructors_form_on_events( $post_type ) {
    
    	// We only want the "Instructors" post type; bail if it's some other post type.
    	if ( 'instructors' !== $post_type ) {
    		return;
    	}
    
    	// Add a Table Row for the Instructor Website to show up below the Instructor Name.
    ?>
    	<tr class="linked-post">
    		<td>Instructor Website:</td>
    		<td>
    			<input type='text' tabindex="<?php tribe_events_tab_index(); ?>" name='linked_instructors[website][]' class='linked-post-website instructors-website' size='25' value='' />
    		</td>
    	</tr>
    
    	<tr class="linked-post">
    		<td>Instructor Website 2:</td>
    		<td>
    			<input type='text' tabindex="<?php tribe_events_tab_index(); ?>" name='linked_instructors[website_2][]' class='linked-post-website-2 instructors-website-2' size='25' value='' />
    		</td>
    	</tr>
    <?php
    }
    
    add_action( 'tribe_events_linked_post_new_form', 'tribe_modify_the_instructors_form_on_events' );
    
    /**
     * Saves the instructor information passed via an event.
     *
     * @param int|null $id ID of instructor
     * @param array $data The instructor data
     * @param string $post_type The post type
     * @param string $post_status The intended post status
     *
     * @return mixed
     */
    function tribe_save_the_instructors_form_on_events( $id, $data, $post_type, $post_status ) {
    
    	// Check to see if we're updating an already-existing instructor post.
    	if ( isset( $data['id'] ) && intval( $data['id'] ) > 0 ) {
    
    		// We're updating an existing post, but only an ID was passed; no other data.
    		// So, just return the ID. Do nothing.
    		if ( count( $data ) == 1 ) {
    			return $data['id'];
    		}
    
    		// Check out the Tribe__Events__Organizer->update() method for inspiration on how to make an "update" function.
    		return example_update_instructor( $data['id'], $data );
    	}
    
    	// Otherwise, we're not updating an existing instructor; we have to make a new instructor post.
    	
    	// Check out the Tribe__Events__Organizer->update() method for inspiration on how to make a "create" function.
    	return example_create_instructor( $data, $post_status );
    }
    
    add_action( 'tribe_events_linked_post_create_instructors', 'tribe_save_the_instructors_form_on_events', 10, 4 );

    this results in the following.
    on the left panel in wordpress dashboard i have an instructor tab (see image for_george)
    i can click on this and it opens a sub menu , instructors and add new.

    if i select add new , all i can do is type in title and also theres the standard wordpress text box , no other fields are present for me to create/edit or type in.

    if i type in a title and hit publish then it is saved , but just a title. see image (for_george_2.jpg)

    from here if i goto add new event i have the following boxes (for_george_3.jpg)
    if i clcik on the box i get the following (for_george_4.jpg)
    so far the instructor field within add event works as expected,i can select previously created instructors and if i type in to create i then get the 2 boxes to type into (for_george_5.jpg)

    so far so good when i hit publish the event , it doesn’t get published , and i am presented with a blank white page.

    i hope that clears it up , i am presuming its because the functions example.etcetc dont exist , do these need to be added to the single.event.php in some way , its so close but for me and my knowledge its a long long way away!! the more i look into it and read this post back the more confused i become (i even printed it out ) :-0), it really is driving me mad, this simple field would drive new and repeat visitorss to my site.

    as always thanks for your time , have a great day ,
    p.s it acts the same way in 2012,13,14,15,6 and 2017 with just the events and pro plugins active

    Posts: 24 Topics: 9
    | Permalink

    heres the 5th image , was capped to 4 sorry

    Posts: 24 Topics: 9
    | Permalink

    ok george i think it all works as it should up to this point i note in previous post this

    Let us know if that helps at least get the “Create or Find” dropdown working!

    As cliff noted, the “create” and “save” functions themselves are ones you’ll have to create, but I can offer some insight on that once we confirm the “Create or Find” dropdown is working for the Instructors linked post type…

    …let us know what you find!

    — George

    so as i see it now thats where its up to . could you offer this insight into these functions?

    thanks again

    Posts: 24 Topics: 9
    | Permalink

    ok george i think it all works as it should up to this point i note in previous post this

    Let us know if that helps at least get the “Create or Find” dropdown working!

    As cliff noted, the “create” and “save” functions themselves are ones you’ll have to create, but I can offer some insight on that once we confirm the “Create or Find” dropdown is working for the Instructors linked post type…

    …let us know what you find!

    — George

    so as i see it now thats where its up to . could you offer this insight into these functions?

    thanks again

    Posts: 10476 Topics: 3
    | Permalink

    Hey Martin,

    Apologies for the delayed response.

    As noted earlier, we cannot help with custom coding. I am glad we were able to help with custom coding thus far despite that policy, but you will have to take the reins from here.

    With that being said, as one final bit of help, I would like to highlight that you have to create the example_update_instructor() and example_create_instructor() functions.

    They currently don’t exist in the sample code you have shared thus far, so your task from here is to make them exist.

    There are some existing functions in our own code that you can use as inspiration. For example, here’s an “Update” function for Organizers that you could use to learn from for Instructors: https://github.com/moderntribe/the-events-calendar/blob/4.6.5/src/Tribe/Organizer.php#L417-L486

    Despite our custom coding policies, I have written more custom code for you herehttps://git.io/vbge8

    Please look at the two new functions at the bottom of the file, example_update_instructor() and example_create_instructor().

    Using this updated code should work well for you. If it does not or other issues persist, you will unfortunately have to take the reins on further refinement and development of your custom features here.

    Best of luck with your project,
    George

    Posts: 24 Topics: 9
    | Permalink

    many many thanks george for your time and effort, unfortunately its not quite right , can you please answer a few questions for me to help me along ??i dare not ask you to do any more coding!! 😉
    1) i try to create the instructor when adding event and i end up on a white screen and the event is never published all i can do is press back button.
    2) i use a previously created instructor and the event is posted successful. how ever on the single event page there is no mention of instructor , should there be ? or do i need to add something to single-event.php to display the instructor details ?
    3) when i get this all working can i click on an instructor like i can venue and organizer and it shows all the upcoming events for this instructor ?

    its so close now !! thx george

    Posts: 11234
    | Permalink

    Martin, I haven’t followed along each reply between you and George, but we have reached the limit of support we’re able to provide to you. As you probably know already, we don’t provide customizations for customers, per our Scope of Support / Terms.

    If you need further coding help, you may want to reference our documentation and list of known customizers.

    Posts: 24 Topics: 9
    | Permalink

    cliff i appreciate all you have done to help me !i dont want any more help coding just 3 little answers so i have something to work towards!! if you could spare 30 seconds to answer i would be eternally grateful simple yes and no will suffice!!
    thanks again martin !!

    Posts: 11234
    | Permalink

    Rereading your previous reply:

    If you ever see a white screen in WordPress, I always recommend for you to enable WP_DEBUG and WP_DEBUG_LOG (which will create a file on your server at /wp-content/debug.log if there are any WP_DEBUG messages) and share any debug messages you see.

    Once a linked post type is properly registered, it should work just like Organizers and Venues do.

    However, you’ll need to alter the template(s) in order to get such information to display. For this information, please reference our Themer’s Guide.

    Posts: 24 Topics: 9
    | Permalink

    many thanks cliff, i think you haveprovided me with more than enough to get this up and running , please accept my thanks!!
    kind regards martin

    | Permalink
    Posts: 11234
    | Permalink

    Excellent! So glad we could go above-and-beyond for you in this one, and thanks to you for pointing out that our Knowledgebase article needs some love. We’ll eventually get to that.

    Have a great rest of your week!

    Posts: 11234
    | Permalink

    Hi, Martin.

    Good news! We’ve significantly modified our Knowledgebase article about Linked Post Types (previously called Abstract Post Types).

    We’ve even provided a working example plugin to get you started.

    Please review it afresh at https://theeventscalendar.com/knowledgebase/linked-post-types/ and open a new support thread if you have any follow-up questions.

    Thanks!

The topic ‘abstract pos’ is closed to new replies.