Support

Account

Forum Replies Created

  • I’m looking to return both the question and the answer in a custom search overlay. For instance, if a customer types in “flavors”, I would like a dynamically populated “card” that has both the question and answer in it, for instance — Q: What flavors do you have? A: Strawberry, Chocolate, etc.

    I have the Javascript / card stuff taken care of, I just can’t seem to return both the Q and A which match a search term in the API.

  • Yeah this is way out of my wheelhouse, and if you’re not sure how, I think I’ll just put a pin in this. It was worth the exploration. Thanks a lot for your assistance, John!

  • No problem! So, I was just playing around with this, and if I grab the fields on the parent field, I get All Fields and Sub Fields of the FAQ page.

    if (get_post_type() == 'page') {
                array_push($results['pages'], array(
                    'title' => get_the_title(),
                    'link' => get_the_permalink(),
                    'faq' => get_field('faq-topic'),
                ));
            }

    Here’s an example of a response:

    "faqs": [
                {
                  "faq_group": {
                       "question": "What are your shop hours?",
                       "answer": "<p><strong>Our shop hours:</strong></p>\n<ul>\n<li>Monday – Thursday: 10-6 PM EST</li>\n<li>Friday: 10-5 PM EST</li>\n<li>Saturday: Closed</li>\n<li>Sunday: Closed</li>\n</ul>\n",
                        "linked_page": ""
                                }
                  }],

    Where I’m really trying to go from here is to access both the question and answer and access them via javascript template literal, which I have working really well. All other post types and their respective fields are working nicely. I’m just struggling with this one.

  • Testing the search queries for keywords unique to the FAQ questions/answers fields return the FAQ page, which I assume means that the plugin is working. If the search query is extending to a repeater field, it’s returning the parent page on which those fields are outputted.

    I’m confused on where to go next, and I appreciate your patience.

    The code in my original post is in a file called search-route.php. I’m assuming the filter you’re talking about in the article is the following:

    /**
     * Modify the search query with posts_where
     *
     * http://codex.wordpress.org/Plugin_API/Filter_Reference/posts_where
     */
    function cf_search_where( $where ) {
        global $pagenow, $wpdb;
    
        if ( is_search() ) {
            $where = preg_replace(
                "/\(\s*".$wpdb->posts.".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
                "(".$wpdb->posts.".post_title LIKE $1) OR (".$wpdb->postmeta.".meta_value LIKE $1)", $where );
        }
    
        return $where;
    }
    add_filter( 'posts_where', 'cf_search_where' );

    Am I correct in thinking that this is the function I need to add to my search-route.php?

  • Thanks, John – I have a plugin installed ‘Better ACF Search’ to get the fields, and that seems to work as if I search for a unique keyword in one of the FAQ fields, I get the FAQ Page as a search result. I’m assuming that plugin is working at this because of that.

    My question now becomes, if I search in meta_key LIKE "faq_%", do I need a new WP_Query for those results, or can I amend my original query?

    I appreciate the help, I’m a little new at this and learning.

Viewing 6 posts - 1 through 6 (of 6 total)