what are you trying to do actually?
this is what you want
[ Moderator note: please wrap code in backticks or use the code button. ]
add_filter('sf_post', 'sf_replace_custom_values', 1, 10);
function sf_replace_custom_values($post) {
$cvalue = get_post_custom_values('KEY', $post->ID);
if(sizeof($cvalue) > 0){
$post->post_cvalue = $cvalue;
}else{
$post->post_cvalue = '';
}
return $post;
}
replace KEY with your custom key field name, and insert {post_cvalue} in your template where you want the custom field value to appear.
you can improve this function more if you are looking for only specific post type, Contact me for details on such development
works perfect. thanks
And to show the category?
please
what do you mean by category?, categories doesn’t have custom values
please give me more details
add_filter('sf_post', 'sf_replace_custom_values', 1, 10);
function sf_replace_custom_values($post) {
$cvalue = get_post_custom_values('KEY', $post->ID);
if(sizeof($cvalue) > 0){
$post->post_cvalue = $cvalue;
}else{
$post->post_cvalue = '';
}
$b = array();
$categories = get_the_category($post->ID);
if($categories){
foreach($categories as $category){
$b[] = $category->cat_name;
}
}
$post->categories = implode(', ', $b);
return $post;
}
add {categories} to the template, should show a list of comma separated category names
It works perfectly
thanks for your soprte that I rate 10
great. I also want to show categories. Where should i add that code? function.php or plugin file? which file? thanks.
another thing – how to show taxonomies instead of categories.
you can add that code anywhere, in you theme functions.php for example
as for taxonomies, the process is not simple and needs some extra work plus knowing the taxonomy slug.
Would this be the same if I was using the WPMUDEV.org CustomPress plugin for custom fields?
What I’m trying to do is allow the search to enable results based on the Custom Field name (e.g. Property ID, Location, etc..).
Thanks
i am not sure, however u can test it like this and see the output
The code works great for posts, but I when I try to use it with documents, the categories do not show up. How can I fix this?
Thanks