Okay
  Public Ticket #3506893
Elementor Loop
Closed

Comments

  •  2
    feriamsidera started the conversation

    Okay, well seems like all functions for meta data and featured images are gone after the update. I can't set a loop to a featured image like I could before, nothing pulls and even if I use a gallery field and select post attachments, I get nothing to show. All the custom code you sent me in the past seems to no longer function with this latest version. Is there an easy fix to get all this stuff accessible for a custom loop or do I need to downgrade?

  •  2
    feriamsidera replied

    Anything on this? 

  •  881
    Zhivko replied

    Sorry for the delay.

    Could you send me the code you were using? 

    I will see if I can modify it for 5.x.



    Stachethemes Developer

  •  2
    feriamsidera replied

    Zhivko, 

    Thank you for the reply the code is below: 

    /**
     * Add custom post meta to event
     * Store event day number, day label and month label in post meta
     * @param int $result - post id
     * @param Event $event
     * @param bool $is_update
     * @return void
     */
    add_action('stec_after_insert_event', function ($result, $event, $is_update) {
        if ( ! is_numeric($result)) {
            return;
        }
        $day_num     = $event->get_start_date('d');
        $day_label   = $event->get_start_date('D');
        $month_label = $event->get_start_date('M');
        $year_label = $event->get_start_date('Y');

        update_post_meta($result, 'stec_event_day_num', $day_num);
        update_post_meta($result, 'stec_event_day_label', $day_label);
        update_post_meta($result, 'stec_event_month_label', $month_label);
        update_post_meta($result, 'stec_event_year_label', $year_label);
        update_post_meta($result, 'stec_event_link_url', $event->get_link('url'));
    }, 10, 3);


    Also, is there a way to make the first image added the featured image? That seems have been the way it worked in the previous version. I like your builder for the pages, but having the ability to make a custom loop to access those pages would be great. 


  •  881
    Zhivko replied

    Here's the code for version 5.x.

    add_action('stec_after_update_event', 'stec_custom_after_event_change', 10);
    add_action('stec_after_create_event', 'stec_custom_after_event_change', 10);
    function stec_custom_after_event_change($event_id) {
        if (!is_numeric($event_id)) {
            return;
        }
        $event_start_date  = get_post_meta($event_id, 'start_date', true); // returns Y-m-h\TH:i
        $timezone          = \Stachethemes\Stec\Helpers::get_event_timezone($event_id);
        $date_object       = new \DateTime($event_start_date, new \DateTimeZone($timezone));
        $day_num           = $date_object->format('d');
        $day_label         = $date_object->format('D');
        $month_label       = $date_object->format('M');
        $year_label        = $date_object->format('Y');
        $external_link     = get_post_meta($event_id, 'external_link', true);
        $external_link_url = $external_link['url'] ?? '';
        update_post_meta($event_id, 'stec_event_day_num', $day_num);
        update_post_meta($event_id, 'stec_event_day_label', $day_label);
        update_post_meta($event_id, 'stec_event_month_label', $month_label);
        update_post_meta($event_id, 'stec_event_year_label', $year_label);
        update_post_meta($event_id, 'stec_event_link_url', $external_link_url);
    }
    
    4808417748.png


    If you want to display the first image as a featured image you can use following filter:

    /**
     * Set first image as featured image for stec_event post type
     */
    add_filter('post_thumbnail_html', function ($html, $post_id, $post_thumbnail_id) {
        if (get_post_type($post_id) !== 'stec_event') {
            return $html;
        }
        $images = get_post_meta($post_id, 'images', true);
        if (!$images) {
            return $html;
        }
        $image_id = array_shift($images);
        if (!is_numeric($image_id)) {
            return $html;
        }
        $image_url = wp_get_attachment_image_src($image_id, 'full')[0];
        $html = '<img src="' . $image_url . '" alt="">';
        return $html;
    }, 10, 3);
    

    Stachethemes Developer

  •  2
    feriamsidera replied

    Zhivko, 

    Thank you the meta data code worked perfects, I "updated" all events and was able to get that setup. 

    The featured image filter is not working for me. I even removed and put new images on the event to trigger the filter but nothing is showing in a loop. 

  •  881
    Zhivko replied

    Okay, try this one then:

    add_filter('stec_after_update_event', 'stec_custom_featured_image', 10);
    add_filter('stec_after_create_event', 'stec_custom_featured_image', 10);
    function stec_custom_featured_image($post_id) {
        if (get_post_type($post_id) !== 'stec_event') {
            return;
        }
        $images = get_post_meta($post_id, 'images', true);
        if (!$images || !is_array($images)) {
            return;
        }
        $image_id = array_shift($images);
        if (!is_numeric($image_id)) {
            return;
        }
        set_post_thumbnail($post_id, $image_id);
    }
    



    Stachethemes Developer

  •  2
    feriamsidera replied

    Zhivko, 

    That worked thanks! I just had to open each post and update them and it worked well. 

  •  2
    feriamsidera replied

    okay in this same thread of conversion to the new calendar setup, Elementor just released an update with a Element Manager baked in, your past version of your plugins directly conflicts with this and won't let the manager load (just hangs). That being said I have a college website I built and is live on your old version. Now I've gone through the process of trying to update in a staging environment to the new builder (migrated with your tool) and the event pages don't load. I've cleared cache etc. Now this is going to be a process since I'll have to update click each calendar entry and hit update to get the post meta data setup like the past, but all the ones I've test so far don't load the builder template. I've even changed the slug to break cache and nothing loads even with a template built as default and selected on the event setup. 

    UPDATE: okay I got the event template to start showing after I bulk exported events and then deleted them and reimported them again. The issue now is the calendar page looks messed up, icons aren't showing etc. 

    I don't mind leaving them on the old setup (it works well for them) as I've already trained their staff on adding events (and while your new setup is better - they don't handle training well). I just need a workaround to let the element manager load for everything else. 

  •  2
    feriamsidera replied

    UPDATE: Cancel all this, I was able to fix the issue by forcing scripts to load by page ID. Should be able to do what I need to do now to get them updated. 

    As an added note, my staging environment won't allow that license to validate as it is already assigned to another domain (sooo most this can because the license is blocking that content from rendering - not sure).