0

I have near 100 custom fields for each post with prefix "wps_" (examle, wps_imagine, wps_video, etc) and near 20 custom fields without prefix.

Problem that I don't know names of custom fields with prefix, because they set by user in admin panel and can be different, user can delete some of them, create, rename, but they always have prefix "wps_". So, I need a function to get all custom fields for one post but only with key prefix "wps_"

How to get all of these custom fields with prefix "wps_" and show them in post?

3
  • You will have to be more specific: This is post related metadata, I assume? Do you want to grab values for one post or all that are saved? May 16 '13 at 8:57
  • Ok, more details. I have near 100 custom fields for each post with prefix "wps_" and near 20 custom fields without prefix. Problem that I don't know names of custom fields with prefix, because they set by user in admin panel and can be different, user can delete some of them, create, rename, but they always have prefix "wps_". So, I need a function to get all custom fields for one post but only with key prefix "wps_".
    – ETNO
    May 16 '13 at 20:36
  • Please edit extensive additional details into your question.
    – Rarst
    May 16 '13 at 20:39
1

Meta function don't support wildcards in keys. You could probably go through SQL, but it would probably be easier to use get_post_custom() to retrieve whole meta and pick out items you need. It is heavily cached inside so it would probably be more robust that custom solution as well.

0
0

This is a simple built-in function for displaying custom fields for the current post, known as the "post-meta" (stored in the wp_postmeta table). It formats the data into an unordered list.

It must be used from within The Loop or in a theme file that handles data from a single post (e.g. single.php). the_meta() will ignore meta_keys (i.e. field names) that begin with an underscore.

<?php the_meta(); ?> 

Output from the_meta:

<ul class='post-meta'>
<li><span class='post-meta-key'>your_key:</span> your_value</li>
</ul>
3
  • this code shows all custom fields for post, but I need only with specific prefix
    – ETNO
    May 17 '13 at 12:25
  • by "get_post_meta" get all post-meta,store it(array variable) and "usset" post-meta that you not want in array variable May 17 '13 at 12:36
  • it can be a solution. But it will be more flexible to get all needed custom fields with no unset. I think regular expression can help but I am not good in it
    – ETNO
    May 17 '13 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.