MB Relationships + Elementor Loops

Support MB Relationships MB Relationships + Elementor LoopsResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #44622
    Marcus PottsMarcus Potts
    Participant

    Hi

    Do you have an example of an Elementor custom query that will retrieve related posts so I can display them on my CPT page using Elementor Loop grid or carousel.

    I have been going round in circles for days.

    Thanks
    Marcus

    #44628
    PeterPeter
    Moderator

    Hello Marcus,

    You can follow an example here https://support.metabox.io/topic/display-mb-view-shortcode-in-an-elementor-loop-template/?swcfpc=1#post-44339

    #44633
    Marcus PottsMarcus Potts
    Participant

    Hi Peter

    Thanks for your speedy response. I have tried to follow the logic in the twig example:

    add_action('elementor/query/related_av_solutions', function($query) {
        $current_av_solution_id = get_the_ID();
    
        if ($current_av_solution_id && get_post_type($current_av_solution_id) === 'av_solution') {
        
            $connected_items = MB_Relationships_API::get_connected([
                'id' => 'posts_to_av_solution', 
                'from' => $current_av_solution_id, 
            ]);
            
            if (!empty($connected_items) && !is_wp_error($connected_items)) {
                $related_post_ids = wp_list_pluck($connected_items, 'ID');
               
                if (!empty($related_post_ids)) {
                    $query->set('post__in', $related_post_ids);
                    $query->set('orderby', 'post__in');
                } else {
                   
                    $query->set('post__in', [0]);
                }
            } else {
               
                $query->set('post__in', [0]);
            }
        }
    }, 10, 1);

    But it just blows my PHP memory limit. Any further help would be really appreciated.

    Thanks
    Marcus

    #44639
    PeterPeter
    Moderator

    Hello,

    The example in that topic uses the Twig code in MB Views and add the View shortcode to the Elementor Loop Grid, not the PHP code with a callback function.

    If it blows the PHP memory limit, you can increase this value https://blog.hubspot.com/website/wordpress-php-memory-limit

    If it still doesn't work, we offer a customization service with an extra fee. You can contact us here to get more details https://metabox.io/contact/

    #44644
    Marcus PottsMarcus Potts
    Participant

    Hi Peter

    Thanks again for your response, I had already increased memory to 1024M and it blew it straight away.

    I'll look at alternate solutions.

    Thanks
    Marcus

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.