[wp-hackers] Select Menu to filter results by Custom Values

Otto otto at ottodestruct.com
Fri Nov 21 22:07:15 GMT 2008


Additional: I re-read your first post, it seems like you want to get
the values for a key meta key for ALL posts, correct?

If so, then there's no way to do that with WordPress functions. Meta
values are post-specific, there's no functions to manipulate them as a
group, they're attached to a post.

You'll need to write a custom SQL query to pull out the data you want.
scribu's post had the correct basic idea. Write some SQL to select the
values, pull them out into an array using $wpdb->get_results, then
loop through them to do your output.

There's no other way to do it, really.


On Fri, Nov 21, 2008 at 4:03 PM, Otto <otto at ottodestruct.com> wrote:
> You're getting back "Array" because when single = false, then it
> returns an array of all the metas for that post with that key.
>
> Simple example of getting more than one meta value:
>
> $timearray = get_post_meta($post->ID, 'time', false);
> foreach ($timearray as $time) {
> echo $time;
> }
>
>
> On Fri, Nov 21, 2008 at 3:32 PM, Kelter-BadCat Design <kelter at badcat.com> wrote:
>> Thanks Jennifer,
>>
>> I've been to these pages already -
>>
>> I seem to get just text returned back stating "Array" when using:
>> <?php echo get_post_meta($post->ID, 'time', $single = false); ?>
>>
>> If I change to --
>> <?php echo get_post_meta($post->ID, 'time', $single = true); ?>
>>
>> It "works" but then I only get the data from the first post delivered to the
>> page.
>>
>> I've even tried variants of...
>> <?php $key="time"; echo get_post_meta($post->ID, $time, $single = true); ?>
>> to no avail.
>>
>> The next step of getting this returned into a select menu also fails.
>>
>> -Kel
>>
>>
>>
>> At 11:42 AM -0800 11/21/08, Jennifer Hodgdon wrote:
>>>
>>> scribu wrote:
>>>>
>>>> Also, you'll have to use a custom query, something like " SELECT * FROM
>>>> $wpdb->postmeta WHERE key='time' "
>>>
>>> I don't think that is necessary. The get_post_meta() function should
>>> return the whole array, and get_post_custom gives you all the post meta in
>>> one big array.
>>>
>>> http://codex.wordpress.org/Function_Reference/get_post_meta
>>> http://codex.wordpress.org/Function_Reference/get_post_custom
>>>
>>>   --Jennifer
>>>
>>> --
>>> Jennifer Hodgdon * Poplar ProductivityWare
>>> www.poplarware.com
>>>
>>> Drupal/WordPress Sites, Themes, Modules/Plugins
>>> Custom Web Programming, Web Databases
>>> PHP, Perl, MySQL, JavaScript, XML, AJAX
>>>
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>


More information about the wp-hackers mailing list