Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author wpdreams

    (@wpdreams)

    Hi!

    Well, I did some experiments, and made a function that works in most cases. Put this into the functions.php file in your active theme directory:

    add_filter('asl_results', 'get_all_the_meta', 10, 1);
    
    function get_all_the_meta( $results ) {
      global $post;
      
      foreach ($results as $k => &$r) { 
        if ($r->content_type != 'pagepost') continue;
        $post = get_post($r->id);
        setup_postdata($post);
        if ( $keys = get_post_custom_keys() ) {
          $r->content .= "<ul class='post-meta'>\n";
          foreach ( (array) $keys as $key ) {
            $keyt = trim($key);
            if ( is_protected_meta( $keyt, 'post' ) )
                   continue;
            $values = array_map('trim', get_post_custom_values($key));
            $value = implode($values,', ');
            $r->content .= apply_filters( 'the_meta_key', "<li><span class='post-meta-key'>$key:</span> $value</li>\n", $key, $value );
          }
          $r->content .= "</ul>\n";
        }
      }
      
      wp_reset_postdata();
      
      return $results;
    }

    I hope it helps!

    Thread Starter borkie

    (@borkie)

    Yes, thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Get custom fields’ is closed to new replies.