• Resolved thegreyspot

    (@thegreyspot)


    HI,

    Love the plugin!

    I am using Advance Custom Fields plugin to add a few extra options to the Events posts. Idealy, I’d like to perform a get like this:

    $featured_events= EM_Events::get( array( 'limit' => 3, 'array'=> true, 'event_attributes' => Array ( 'publish_to_university_homepage' => 1 , 'university_homepage_featured_event' => 1 ) ) );

    But that completely ignores my Event_attributes stuff. You can see my custom fields show up in the event object like so:

    ...
    [event_date_modified] => 2014-01-12 17:13:10 [event_attributes] => a:1:{s:30:"publish_to_university_homepage";s:1:"0";} [blog_id] => 1 [group_id] => 0 [recurrence] => 0 [recurrence_interval] => [recurrence_freq]

    Do you think this is possible?
    Thanks!
    https://www.ads-software.com/plugins/events-manager/

Viewing 15 replies - 1 through 15 (of 19 total)
  • Hi,

    Glad you’re enjoying the plugin.

    What do you mean when you say, “But that completely ignores my Event_attributes stuff”. You mean it ignores custom attributes / fields you’ve added using Events Manager?

    Thread Starter thegreyspot

    (@thegreyspot)

    It just lists all of events and ignores the “publish_to_university_homepage =>1” attribute i have in my get() request.

    Keep in mind, I added this custom field using Advanced Custom Fields (ACF), and NOT the events Manager custom fields. I did this because it made it easier with the other fields I have for posts. Do I need to use the Events Manager custom fields? If so, how would I form the get requests in this case? And can I apply the same custom fields across my whole multisite network?

    Thanks

    Plugin Support angelo_nwl

    (@angelo_nwl)

    maybe you can try additional coding like

    if ( in_array('news',$featured_events->event_attributes) ){ 
    
    }else{
    
    }
    Thread Starter thegreyspot

    (@thegreyspot)

    You mean grab a couple of events and then filter through them with this kind of if statement?

    That would be sort inconvenient, because I wont know how many posts to grab before finding what i need.

    Thanks

    I think Angelo means you’d just use that code in an if statement to discard, or keep, the events you wanted.

    Thread Starter thegreyspot

    (@thegreyspot)

    Right thats what I understood too? But I’m saying that wouldn’t be very efficient. Do you have any recommendations on how I should do my search? Should I just go day by day until i have the number of events I want?

    Thread Starter thegreyspot

    (@thegreyspot)

    I am trying to do what Angelo_nwl suggested. However, I don’t know how to parse

    [event_attributes] => a:1:{s:30:"publish_to_university_homepage";s:1:"0";}

    Which is what is in my EM_Events array. PHP thinks its a string, so I can’t use in_array…

    Any ideas?

    Plugin Support angelo_nwl

    (@angelo_nwl)

    you can use php serialize() – https://www.php.net/manual/en/function.serialize.php

    eg.

    $event_attributes = serialize ($featured_events->event_attributes);
    if ( in_array('news',$event_attributes) ){ 
    
    }else{
    
    }

    Thread Starter thegreyspot

    (@thegreyspot)

    @angelo_nwl I did that but in_array complains that its still a string. So I’m guessing it was able to serialize?

    I mean, this doesnt look very normal to me:
    [event_attributes] => a:1:{s:30:”publish_to_university_homepage”;s:1:”0″;}

    Where are you using that code? I think it would be helpful to see the chunk of code you’re using.

    Thread Starter thegreyspot

    (@thegreyspot)

    function getEventsWithFilter($limit, $conditions, $blog = ""){
    	$grab = 5;
    	$offset = 0;
    	$events = [];
        while(count($events) < $limit){
        	$tempEvents = EM_Events::get( array('limit' => $grab,
        										'offset'=> $offset,
        										'blog' => $blog,
        										'array'=> true));
        	if(count($tempEvents) == 0)
        		break;//no more events to save
        	//print_r($tempEvents);
        	foreach($tempEvents as $tempEvent){
        		$EA = serialize($tempEvent['event_attributes']);
        		print_r($EA);
        		if($EA){
        			foreach($conditions as $condition){
        				//echo $condition;
        				if(in_array("publish_to_university_homepage", $EA))
            				array_push($events, $tempEvent);
            		}
            	}
            }
            $offset += $grab;
        }
    
        //Trim off extra arrays, since we do 2 at a time
        return array_slice($events, 0, $limit);
    }

    This gives me this error on the in_array line:

    Warning: in_array() expects parameter 2 to be array, string given in

    Also the print_r, clearly looks like an string.

    Does that help? Thanks

    Plugin Support angelo_nwl

    (@angelo_nwl)

    you need

    $tempEvents->event_attributes

    instead of

    $tempEvent['event_attributes']

    Thread Starter thegreyspot

    (@thegreyspot)

    Yes I have tested that too.

    function getEventsWithFilter($limit, $conditions, $blog = ""){
    	$grab = 5;
    	$offset = 0;
    	$events = [];
        while(count($events) < $limit){
        	$tempEvents = EM_Events::get( array('limit' => $grab,
        										'offset'=> $offset,
        										'blog' => $blog,
        										'array'=> true));
        	if(count($tempEvents) == 0)
        		break;//no more events to save
        	//print_r($tempEvents);
        	foreach($tempEvents as $tempEvent){
        		$EA = serialize($tempEvent->event_attributes);
        		print_r($EA);
        		if($EA){
        			foreach($conditions as $condition){
        				//echo $condition;
        				if(in_array("publish_to_university_homepage", $EA))
            				array_push($events, $tempEvent);
            		}
            	}
            }
            $offset += $grab;
        }
    
        //Trim off extra arrays, since we do 2 at a time
        return array_slice($events, 0, $limit);
    }

    Gives this as output (repeated multiple times):

    N;
    Warning: in_array() expects parameter 2 to be array, string given in /Users/thegreyspot/Workroom/wnmu/wp-content/themes/wnmu/lib/custom.php on line 166

    What are you getting for print_r($EA); ?

    Thread Starter thegreyspot

    (@thegreyspot)

    Thats what the “N;” is… no idea what that means! haha

    [Moderator Note: No bumping, thank you.]

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Filter custom fields using EM_Events:get’ is closed to new replies.