Do I get this function right? I can't get what I want.
$data_list = elgg_get_entities_from_metadata(array('types'=>'object','subtypes'=>'selldata', 'limit'=>1, 'metadata_name_value_pairs' =>array('name'=>'month', 'value' => 2010-03)));
Or multiple
$data_list = elgg_get_entities_from_metadata(array('metadata_names'=>array('month','name' 'metadat_values'=>array('2010-03','John')));
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by RaĆ¼l Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
There are a few problems. First, you need to quote '2010-03' or PHP will interpret it as 2007 (2010 *minus* 03). Since you are only using one metadata name/value pair, you also should change that call to:
or:
The second statement has a typo in the 'metadata_values' field, and probably doesn't do exactly what you want because name isn't available metadata for a user. (Using multiple names and values doesn't do what you want in this case anyway--It's an OR statement instead of an AND. Use metadata_name_value_pairs.) I'm not sure what you want the second call to return...
You might want to review the documentation on the metadata system: http://docs.elgg.org/wiki/Engine/DataModel/Metadata
Brett, I finnally get it works like this:
elgg_get_entities_from_metadata(array('types'=>'object', 'subtypes'=>'selldata', 'limit'=>1, 'metadata_names' =>array('name','month'), 'metadata_values' =>array($name,$month), 'owner_guid'=>get_loggedin_userid()));
Thanks.
Glad it's working for you but there are a still a few problems:
First, this statement will fail if a non-logged in user looks at that page--It will either return nothing or return all matches ignoring the owner. Make sure you put a check to see if the user is logged in before calling this function.
Second, use metadata_name_value_pairs. This statement doesn't do what you want and only works by chance. The SQL generated by this statement will be something like:
You want SQL to be:
A name/value pair will look like:
...and will generate what you want.
Thanks your suggestion and guidance, Brett.
I found this function not work indeed.
for example: if there are 3 entities, only one entity match what I need, and the other two are empty. the function will also return 3 result, but the other two will use the value of the match one.
I had even tested Brett's suggestion, not work too:
The following is my current codes:
It seems that either $name or $month matches, the results will be returned.
If the datas are:
if I want to get entity with $name='John' and $month='2010-03', the result returns:
@jdleung - It's very hard to help debug this because we don't know how your plugin saves its data. Can you post the code you're using to save information?
Brett, here is it
$name, $sell and $pv are array, since the design is one form for multi input.
It takes me a long time to get it really works now, a 'operand' => '=' is needed!
I realize this thread is old - but it is one of the top google results on this topic. The code for v1.7.8 should be "metadata_name_value_pairs" not "metadata_name_value_pair".
- Previous
- 1
- 2
- Next
You must log in to post replies.