Elementor - Listing Chosen Posts

Support MB Elementor Integrator Elementor - Listing Chosen PostsResolved

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #48196
    Simon FeldmanSimon Feldman
    Participant

    Dear Admin and fellow users!

    I'm after guidance on the best way to achieve the following.

    Setup:

    As a custom field on a posts page I have 'posts' selected. I then within that post can choose other posts of relevance that I want to display as internal links in that blog post

    (setting all this up is ok)

    Question:

    What is the best way to then display the selected posts on that posts page??

    1) If I setup a repeater group field and use the metabox skin, how can I set it up to pull the following from the selected posts using elementor.

    Post Title
    Post Link
    Post Featured Image
    Post Excerpt

    2) Or would I be better trying to setup a filter and use a posts display widget with the custom filter query. (Please note it should only display the selected posts on that page, and not across the site using that custom field)

    #48197
    Simon FeldmanSimon Feldman
    Participant

    Some images for reference:

    #48203
    PeterPeter
    Moderator

    Hello Simon,

    Thanks for reaching out.

    If you use the single field post, not a subfield in a group field, you can use the Text widget to output the field value the frontend with a simple format/style.

    If you use the group field, you can create the skin to display subfield values in a template. I think point 1 would be better.

    Regarding the Group Skin, I see you do not select the Group Skin to use the skin on the template, see this screenshot https://imgur.com/zRHIUQH
    can you please recheck this?

    #48207
    Simon FeldmanSimon Feldman
    Participant

    Hi Peter,

    Thanks for getting back to me so quickly.

    I'm happy with how to use the skin and choose one.

    My questions is how do I pull the post link for the button of a skin, the featured image and the excerpt?

    #48215
    PeterPeter
    Moderator

    Hello Simon,

    You can simply add a Text or Heading widget and select data from Meta Box field post to display the title and link to the post. However, it doesn't support getting other post data like featured image, excerpt ...

    #48217
    Simon FeldmanSimon Feldman
    Participant

    Hey Peter, thank you so much for getting back to me so quickly. Is it possible to use it for a search query in in a filter? And for it to just return the query for posts from that specific custom field for that post onlyand not the whole website?

    I hope you can understand what I’m trying to achieve here. Being able to pull the post from that custom field. I can use a different widget that displays posts using a search query/filter then I’ll be able to get all that data that I need and display it with the featured image.

    Thank you again for all your help is really appreciated if I can leave feedback or review somewhere to help you guys please let me know. All the best, Simon.

    #48220
    PeterPeter
    Moderator

    Hello,

    I understand that you want to filter posts by the post custom field. Basically, it is possible. You can use a third-party that is compatible with Meta Box like FacetWP to create a filter posts by a field value.
    https://metabox.io/plugins/meta-box-facetwp-integrator/

    #48260
    Simon FeldmanSimon Feldman
    Participant

    Hiya I thought I'd share the query which got this to work if you want to reference it elsewhere for users trying to do the same.

    Using the post field and set it up as cloneable if you want multiple internal links.
    Custom field ID of mb_lnk_int
    Use a post widget of your choice and the custom query "mb_internal_links_filter"

    Then create this snippet

    
    /**
     * Filter to get posts referenced in the mb_lnk_int MetaBox post field
     * This function retrieves posts linked in the current post's mb_lnk_int field
     * 
     * @param array $query_args The original query arguments
     * @return array Modified query arguments
     */
    function filter_internal_linked_posts($query_args) {
        // Get the current post ID
        $current_post_id = get_the_ID();
        
        // If no current post ID is available (like on archive pages), return original args
        if (!$current_post_id) {
            return $query_args;
        }
        
        // Get the linked posts from current post's meta field
        $linked_posts = get_post_meta($current_post_id, 'mb_lnk_int', true);
        
        // If no linked posts or empty value, ensure no results by using non-existent ID
        if (empty($linked_posts)) {
            $query_args['post__in'] = array(0); // Will return no results
            return $query_args;
        }
        
        // Convert to array if it's a single value
        if (!is_array($linked_posts)) {
            $linked_posts = array($linked_posts);
        }
        
        // Set up query to get only the posts that are referenced in current post's mb_lnk_int
        $extra_query = array(
            'post__in' => $linked_posts,
            'post_type' => 'any', // Get any post type that is referenced
        );
        
        // Merge with existing query args, prioritizing our filter
        $query_args = array_merge($query_args, $extra_query);
        
        return $query_args;
    }
    add_filter('mb_internal_links_filter', 'filter_internal_linked_posts');
    
Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.