• Hello,
    I try to understand how the plugin is able to display only the events that are public for some groups and not the others.
    For another page, I need to display only the events that are public according to the visitor’s group, but I can not find the missing argument in my query :

    <?php 
    					// THE LOOP :
                        $posts_per_page = woffice_get_settings_option('blog_number');
    
    					$pagination_slug = (is_front_page()) ? 'page' : 'paged';
    					$paged = (get_query_var($pagination_slug)) ? get_query_var($pagination_slug) : 1;
    
                        /**
                         * Filter args of the blog posts query
                         *
                         * @param array $args
                         * @param int $paged
                         * @param int $posts_per_page
                         */
    					$args = apply_filters('woffice_blog_query_args', array(
    						'post_type' => 'event',
    						'orderby'    => 'meta_value',
    						'meta_key'   => '_event_start_date',
    						'paged' => $paged,
                            'posts_per_page' => $posts_per_page
    					), $paged, $posts_per_page);
    
    					$blog_query = new WP_Query($args);
    					if ( $blog_query->have_posts() ) :	?>
    						<?php while ( $blog_query->have_posts() ) : $blog_query->the_post(); ?>
    							<?php // We check for the role : 
    							if (woffice_is_user_allowed()) { ?>
    								<?php 
    								
    								$blog_listing_content = woffice_get_settings_option('blog_listing_content','excerpt');
    								?>
Viewing 13 replies - 1 through 13 (of 13 total)
  • Hi,

    You’ll probably want to take a look at the files contained within:

    /events-manager/buddypress

    Looking at this file should help:

    /events-manager/buddypress/bp-em-groups.php

    Thread Starter topitoconnectey

    (@topitoconnectey)

    Ok thank you !
    If I understand correctly, here this is the function that checks whether the user is a part of the group and should see the event or not : function `bp_em_private_event_check($template){
    global $post, $wpdb, $wp_query, $bp;
    if( $post->post_type == EM_POST_TYPE_EVENT ){
    $EM_Event = em_get_event($post);
    //echo “<pre>”; print_r($EM_Event); echo “</pre>”; die();
    if( !empty($EM_Event->event_private) && !empty($EM_Event->group_id) ){
    if( is_user_logged_in() ){
    //make sure user is a member of this group, whether private or not, private groups just aren’t shown to non-members of a group
    $id_lookup = $wpdb->get_var( $wpdb->prepare( “SELECT m.group_id FROM {$bp->groups->table_name_members} m WHERE m.group_id = %s AND m.user_id = %d AND m.is_confirmed = 1 AND m.is_banned = 0”, $EM_Event->group_id, get_current_user_id() ) );
    if($id_lookup != $EM_Event->group_id){
    unset($post);
    $wp_query->set_404();
    $template = locate_template(array(‘404.php’),false);
    }
    }else{
    unset($post);
    $wp_query->set_404();
    $template = locate_template(array(‘404.php’),false);
    }
    }
    }
    return $template;
    }`

    What is ‘$template‘ and how can I use the function in another page template ?

    Plugin Support angelo_nwl

    (@angelo_nwl)

    this function is added to hook/filter single_template which you can find in php file under classes/em-event-post.php

    Thread Starter topitoconnectey

    (@topitoconnectey)

    I’m not sure you understood my question correctly ? Because single_template seems to display an event as a page ?

    If I can explain again :

    – I have buddypress groups, that are all private.
    – Each event is assigned to a group and should only be visible to the group users.
    – I created a custom page template to display a list of events (copied from the way my theme shows news), but it displays all of the event to every users, regardless of the groups they are in.

    I think this is a normal feature from EM to display events only to the right users no?

    This is how I query the events for the page template, where I’m probably wrong ?

    $args = apply_filters('woffice_blog_query_args', array(
        'post_type' => 'event',
        'orderby'    => 'meta_value',
        'meta_key'   => '_event_start_date',
        'paged' => $paged,
        'posts_per_page' => $posts_per_page
    ), $paged, $posts_per_page);

    Unless I misunderstand what you’re trying to do, you could do this by using the [events_list] shortcode with the group attribute:

    https://wp-events-plugin.com/documentation/event-search-attributes/

    Thread Starter topitoconnectey

    (@topitoconnectey)

    Oh yes this is closer to what i’m trying to do ! Using the group attribute with the ‘my’ is exactly what I need ! Thank you.

    What does the event_list shortcode output ? Is it an array of posts or is there also an HTML structure ? Because I need to keep a specific HTML structure, I was trying to use a query. If the shortcode returns an array I think I’ll be fine.

    What would be the WP_query argument that equals to group=’my’ ?

    Plugin Support angelo_nwl

    (@angelo_nwl)

    shortcode [event_list] will output a list of events which you can change the format under dashboard Events > Settings > Formatting > Events

    Thread Starter topitoconnectey

    (@topitoconnectey)

    I will look into it, thank you.
    But could you still tell me what would be the WP_query argument that equals to group=’my’ ?

    Plugin Support angelo_nwl

    (@angelo_nwl)

    you can find ‘my’ argument under events-manager/buddypress/bp-em-groups.php function bp_em_group_events_build_sql_conditions()

    Thread Starter topitoconnectey

    (@topitoconnectey)

    If I purchase a pro license, could you provide me with a little more details ? The function you gave me is an SQL query and i’m not sure how to use it with WP_Query.
    It’s honestly not such a big issue as it’s something you’ve already done.

    Hope you can help, thank you ??

    Sorry, we’re not able to offer in depth assistance with custom coding issues, even for Pro customers.

    That said, the answer to your question is in the file Angelo mentioned under the segment marked:

    //deal with private groups and events

    There’s no one specific query that deals with groups, it’s built dynamically by this file.

    Thread Starter topitoconnectey

    (@topitoconnectey)

    Oh that’s a shame, I feel really close to the solution but can’t seem to find it. But I understand your position.

    On StackOverflow, someone suggested to “translate” the SQL query into a WP_Query 'meta_query', only if the information is saved in the certain way in the database.

    Could you confirm that if I use nested meta_queries like this, it could work ?

    $meta_query = array(
    	'relation' => 'OR',
    	array(
    		'key'     => 'event_private',
                    'value'   => '0',
    		'compare' => '=',
    	),
    );

    Thank you and sorry for asking too many questions

    Thread Starter topitoconnectey

    (@topitoconnectey)

    I tried to “translate” the query. It’s returning 0 results but I’m not sure if it comes from me “translating” badly, or if the database structure is not made in a way that allows me to query those events like this ?

    if (is_user_logged_in()) {
        global $wpdb;
        // find out what private groups they belong to, and don't show private group events not in their memberships
        $group_ids = BP_Groups_Member::get_group_ids(get_current_user_id());
        if ($group_ids['total'] > 0) {
            // $conditions['group_privacy'] = "(<code>event_private</code>=0 OR (<code>event_private</code>=1 AND (<code>group_id</code> IS NULL OR <code>group_id</code> = 0)) OR (<code>event_private</code>=1 AND <code>group_id</code> IN (".implode(',',$group_ids['groups']).")))";
            $meta_query = array(
                'relation' => 'OR',
                array(
                    'relation' => 'OR',
                    array(
                        'key' => 'event_private',
                        'value' => 0,
                        'compare' => '=',
                    ) ,
                    array(
                        'relation' => 'AND',
                        array(
                            'key' => 'event_private',
                            'value' => 1,
                            'compare' => '=',
                        ) ,
                        array(
                            'relation' => 'OR',
                            array(
                                'key' => 'group_id',
                                'compare' => 'NOT EXISTS',
                                'value' => 'null',
                            ) ,
                            array(
                                'key' => 'group_id',
                                'compare' => '=',
                                'value' => '0',
                            ) ,
                        ) ,
                    ) ,
                ) ,
                array(
                    'relation' => 'AND',
                    array(
                        'key' => 'event_private',
                        'value' => 1,
                        'compare' => '=',
                    ) ,
                    array(
                        'key' => 'group_id',
                        'value' => $group_ids['groups'], //array
                        'compare' => 'IN',
                    ) ,
                ) ,
            );
        }
        else {
            // find out what private groups they belong to, and don't show private group events not in their memberships
            // $conditions['group_privacy'] = "(<code>event_private</code>=0 OR (<code>event_private</code>=1 AND (<code>group_id</code> IS NULL OR <code>group_id</code> = 0)))";
            $meta_query = array(
                'relation' => 'OR',
                array(
                    'key' => 'event_private',
                    'value' => 0,
                    'compare' => '=',
                ) ,
                array(
                    'relation' => 'AND',
                    array(
                        'key' => 'event_private',
                        'value' => 1,
                        'compare' => '=',
                    ) ,
                    array(
                        'relation' => 'OR',
                        array(
                            'key' => 'group_id',
                            'compare' => 'NOT EXISTS',
                            'value' => 'null',
                        ) ,
                        array(
                            'key' => 'group_id',
                            'compare' => '=',
                            'value' => '0',
                        ) ,
                    ) ,
                ) ,
            );
        }
    }
Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘How to hide some event by the query?’ is closed to new replies.