Support » Fixing WordPress » Free version of Relevanssi doesn’t show ACF fields

  • Resolved StephenEquus

    (@stephenequus)


    I understand the Premium version of Relevanssi has support for ACF fields built in but I have the free version. I’m working on a way to grab the information from the database and then spit it out on the search results page. This is what I have come up with so far:

    
    /************** FUNCTIONS.PHP ****************/
    
    // Relevanssi does not show ACF fields - this is a work-around for specific fields in the DB
    function excerpt_function($content, $post, $query) {
        global $wpdb; 
    
        // Grab everything in the ACF content fields from the DB and spit it out in the search result excerpt. If new ACF modules/fields are added in the future then they need to have their 'modules_#_name_name_content' and so on added to show up in the Relevanssi search.
        $fields = $wpdb->get_col("SELECT DISTINCT(meta_key) FROM $wpdb->postmeta WHERE meta_key LIKE '%_content' AND NOT '_modules%'");
        foreach($fields as $key => $field){ 
            $field_value = get_post_meta($post->ID, $field, TRUE); 
            $content .= ' ' . ( is_array($field_value) ? implode(' ', $field_value) : $field_value ); 
        }
        return $content; 
    }
    add_filter('relevanssi_excerpt_content', 'excerpt_function', 10, 3);
    

    This part of the db query is working great:
    $fields = $wpdb->get_col("SELECT DISTINCT(meta_key) FROM $wpdb->postmeta WHERE meta_key LIKE '%_content'

    I’m getting content from ACF fields in my search results pages – but:
    AND NOT '_modules%'");

    isn’t stopping content. The meta_value of these fields is like ‘field_############’ nonsense I don’t want in my search results. I’m working on understanding how SQL AND, OR and NOT Operators work together.

    • This topic was modified 5 months ago by  Jan Dembowski.
    • This topic was modified 5 months ago by  Jan Dembowski. Reason: Fixing formatting

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • StephenEquus

    (@stephenequus)

    Just solved it:

    AND meta_key NOT LIKE ‘_modules%'”);

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Moved to Fixing WordPress, this is not a Developing with WordPress topic. Please do not use Developing with WordPress for plugin specific topics.

    Next time post in that plugin’s sub-forum.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.