Support Forum » User Profile

Forum Replies Created

Viewing 8 posts - 16 through 23 (of 23 total)
  • Author
    Posts
  • in reply to: Query advanced select field by relationship #33572
    Ryan MaiettaRyan Maietta
    Participant

    Hi,

    I know the Meta Box team is on vacation, so I don't want to bother them. They deserve some time off and I'm posting this here in case anyone has encountered this or knows what to do.

    I tried writing my issue out a few times with no luck, so I made a quick video trying to show the problem I'm facing.

    The video: https://www.loom.com/share/144db4819f284c7eb41535bc1a9b016c

    The code: https://pastebin.com/aYjmCN0q

    Does anyone have suggestions or ideas on what could be going wrong?

    in reply to: Query advanced select field by relationship #33504
    Ryan MaiettaRyan Maietta
    Participant

    I can't thank you enough for your help. Everything is working as expected – loving the "multiple" option as well. Everything is solved now, and I've learned so much from your responses and from tackling this project.

    Thank you again and have a wonderful day!

    in reply to: Query advanced select field by relationship #33494
    Ryan MaiettaRyan Maietta
    Participant

    I spoke too soon about my solution for Scholars working – it only pulls in one scholar connected to one course, regardless of any others. What do I need to change so the Advanced Select field creates options for any/all scholars in a relationship with the courses on the event?

    Thank you so much for any time and assistance.

    in reply to: Query advanced select field by relationship #33493
    Ryan MaiettaRyan Maietta
    Participant

    Thank you so much – this worked perfectly. I submitted the link to the old rendition of the website if you want to take a look at the setup. I can explain further why I feel this was the best choice if you'd like.

    I was also able to filter the other Advanced Select field based off scholars linked to courses using some additional code:

    $course_args = array(
            'post_type' => 'course',
            'relationship' => array(
                'id'   => 'event-to-course-relationship',
                'from' => $post_id,
            ),
        );
     
        $course_query = new WP_Query($course_args);
     
        if ($course_query->have_posts()) {
     
            while ($course_query->have_posts()) {
     
                $course_query->the_post();
     
                $course_post_id = get_the_ID();
            }
        }

    And:

    'query_args' => array(
                                'relationship' => array(
                                'id'   => 'from-course-to-scholar',
                                'from' => $course_post_id,
                            ),

    The whole code is located here:
    https://pastebin.com/4sayJwyR

    Thank you again for your help. And just to make sure, is there anything wrong with the code I used? Will it cause any errors?

    in reply to: Query advanced select field by relationship #33480
    Ryan MaiettaRyan Maietta
    Participant

    I still don't have the solution - this is still not working as wanted and assistance is still needed.

    I was able to query courses connected to an event; but, only by manually inputting the Post ID. See below:

    <?php
    add_filter( 'rwmb_meta_boxes', 'qrsi_select_advanced' );
    
    function qrsi_select_advanced( $meta_boxes ) {
        $prefix = '';
    
        $meta_boxes[] = [
            'title'      => __( 'QRSI2', 'your-text-domain' ),
            'id'         => 'qrsi2',
            'post_types' => ['events'],
            'include'    => [
                'relation'       => 'OR',
                'event-category' => [15],
            ],
            
            'fields'     => array(
                array(
                    'name' => __( 'Courses Block 1', 'your-text-domain' ),
                    'id'   => $prefix . 'courses_block_1',
                    'type' => 'post',
                    'post_type' => 'course',
                    'field_type' => 'select_advanced',
                    'placeholder' => __( 'Select an Item', 'your-text-domain'),
                    'query_args' => array(
                        'relationship' => array(
                            'id'   => 'event-to-course-relationship',
                            'from' => 60,
                        ),
                        'post_status' => 'publish',
                        'posts_per_page' => - 1,
                        'order' => 'ASC',
                        'orderby' => 'name',
                    )
                )
            )
        ];
    
        return $meta_boxes;
    }
    
    ?>

    Neither get_the_ID() or get_queried_object_id() worked. I was unable to figure out the $from and $to IDs mentioned in the documentation – there were no examples that showed how to find what the or what they would be. It just said to use them, which isn't a useful direction to provide. Nonetheless, I tried from_event-to-course-relationship and event-to-course-relationship_from as options. Neither worked.

    Manually inputting the events doesn't really work for this purpose. What's the correct way to do this?

    I appreciate the concern behind the reasoning of why; but, right now, I need the how more than anything. I can further expand on the reason after I get this code working as intended.

    Thank you.

    in reply to: Query advanced select field by relationship #33468
    Ryan MaiettaRyan Maietta
    Participant

    Each event has around 20 courses, over the span of 3-5 days. Each day on the schedule contains at least 4 courses, each course with one scholar (some courses are taught by several scholars, depending on the year).

    From what I can tell, there's no easy way to group the courses by day (which change per event). While a taxonomy or different relationships would work, it is much easier to do it via the Advanced Select Field. Please trust me on this - this event system is complicated and it needs to be user-friendly.

    What code would I need to achieve what was mentioned in the original post?

    Thank you very much for your time and any assistance,
    Ryan

    in reply to: Custom field group on CPT under a custom taxonomy term #33081
    Ryan MaiettaRyan Maietta
    Participant

    Nevermind – I posted this very late my time and it was painfully simple. I had the primary rule set to "Taxonomy" -> "Event Category" instead of "Post Type" -> Event. Very silly mistake on my part.

    Ryan MaiettaRyan Maietta
    Participant

    Thank you, I ended up going with that setup!

Viewing 8 posts - 16 through 23 (of 23 total)