Support

Account

Home Forums Backend Issues (wp-admin) Filter Backend PostObject Selection by other Selection and Greetings

Unread

Filter Backend PostObject Selection by other Selection and Greetings

  • Okay first of all good evening to you all. It’s nice to know a place where I can discuss with likeminded. I hope you can help me with my problem:

    The Base
    I have 3 different kinds of custom post types: courses, lessons and topics
    With ACF-Fields I created some relationships between instances of the post types mentioned above.

    In courses I link some students (normal wp-users) to the course. (I already wrote an access-filter with that student-course relationship by the way).

    Next there are lessons. Each lesson is linked to a course und has many topics.

    The students has a repeater-field on their edit-profile page only the admin can see for the grades the students got for a lesson. The field works like this:

    1.) Add new course-grading (once per semester) -> Choose a course (post_object-field)
    2.) Now add a new grade (repeater-subfield) -> Choose the lesson you want to note a grade for (post_object-field) -> Select a grade

    What I want
    Until this point everything works fine but now I have a problem I cannot solve for 3 days and really .. lots of googling, finding, trying, reading and trying again.

    How can I filter the lesson selection in step 2.) by the course-choice from step 1.)???

    Like:

    COURSE SELECT
    Course 1 (Selected)

    LESSON SELECT
    Course 1 linked Lesson A
    Course 1 linked Lesson B
    Course 1 linked Lesson C

    I would post code I tried but beleive me, I tried so many snippets and ideas and I really have no idea where to start. Litterally no idea. Which filter for example should I use?

    Please help me solving that problem. My first attempt was the post-object filter and it looks like this semi-pseudo:

    add_filter('acf/fields/post_object/result/name=graded-lesson', 'my_post_object_result', 10, 4);
    
    function my_post_object_result( $result, $object, $field, $post ) {
    	
        /* Get ID of selected course */
        /* if (id of linked course == ID of selected course above) */
    	    return $result;
        /* else */
                return NULL;
        /* endif */
    
    }

    Okay I think this post is long enough 🙂 I would be happy if I can read some nice replies and I am looking forward to that!

    Good night!!
    Toby

Viewing 1 post (of 1 total)

The topic ‘Filter Backend PostObject Selection by other Selection and Greetings’ is closed to new replies.