Support » Plugin: Ajaxy Live Search » Retrieve values for a custom post field.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Naji Amer

    (@n-for-all)

    what are you trying to do actually?

    gallurt

    (@gallurt)

    show in the search results by custom post field

    Image sample
    http://www.pedretosko.es/wp-content/uploads/2013/10/search.jpg

    Plugin Author Naji Amer

    (@n-for-all)

    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

    gallurt

    (@gallurt)

    works perfect. thanks

    And to show the category?
    please

    Plugin Author Naji Amer

    (@n-for-all)

    what do you mean by category?, categories doesn’t have custom values

    please give me more details

    gallurt

    (@gallurt)

    Plugin Author Naji Amer

    (@n-for-all)

    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

    gallurt

    (@gallurt)

    It works perfectly
    thanks for your soprte that I rate 10

    kumar74

    (@kumar74)

    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.

    Plugin Author Naji Amer

    (@n-for-all)

    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.

    abandoned

    (@thedirector227)

    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

    Plugin Author Naji Amer

    (@n-for-all)

    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

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Retrieve values for a custom post field.’ is closed to new replies.