Okay
  Public Ticket #2808902
include calendar
Closed

Comments

  • breakrocks started the conversation

    Hi,

    Can I include calendar by the calendar's name instead of the id?

    I want to make it includes dynamic calendar, since I don't know the id of all calendars. I think if I can include calendar by the calendar's name, then problem will be solved. Or if you have other way to do it?

    Thanks

  •  877
    Zhivko replied

    Hi,

    It's not possible via name because there could be two calendars with identical names.

    Could you elaborate what's the goal? 

    You need to display the events from currently logged-in user calendar?


    Stachethemes Developer

  • breakrocks replied

    Hi,

    Thanks for replying 

    Yes, I want to dynamically display calendar for currently logged-in user. Can I do that?

    Thanks

  • breakrocks replied

    Hi,

    Just want to know how is going so far, didn't get reply for a while.

    Thanks

  •  877
    Zhivko replied

    Place the custom filter in your theme or child-theme functions.php file:

    /**
     * STEC MOD: Assigns cal attribute to currently logged-in user calendar
     * Shortcode example: [stachethemes_ec dynamic_cal=1]
     */
    add_filter('stachethemes_ec_atts', function($atts) {     if ( !is_array($atts) || !isset($atts['dynamic_cal']) ) {
            return $atts;
        }
        
        $atts['cal'] = -1; // lets default to non-existent calendar
                
        if ( !is_user_logged_in() ) {
            return $atts;
        }     $current_user_id = get_current_user_id();
        $userdata        = get_userdata($current_user_id);
        $calendar_name   = sprintf('%s\'s calendar', $userdata->display_name);     $results = get_posts(array(
            'posts_per_page' => -1,
            'post_type'      => 'stec_calendar',
            'fields'         => 'ids',
            'name'           => $calendar_name
        ));
        
        if (!$results) {
            return $atts;
        }
        
        $calendar_id = array_pop($results);
        
        $atts['cal'] = $calendar_id;
        
        return $atts;
    });

    Then on the page where you want to display the dynamic calendar add dynamic_cal=1 to the shortcode. Example:

    [stachethemes_ec dynamic_cal=1]




    Stachethemes Developer