Home Forums Add-ons Options Page Search through option fields


Search through option fields

    • nifel

    • November 14, 2018 at 8:05 pm

    I am creating my own theme and am trying to use the WordPress search form to find option fields.

    So far I have managed to get the option field into the wp_postmeta database, by doing this:

         'post_id'       => '300'

    My problem is displaying it after a search. Now my search.php looks something like this:

    $query = new WP_Query( array( 's' => get_search_query() ) );
    if ( $query->have_posts() ) {
            _e("<h2>Search Results for: ".get_query_var('s')."</h2>");
            while ( $query -> have_posts() ) {
               $query -> the_post();
                            <a href="<?php the_permalink(); ?>">
                                  <?php the_title(); ?>

    My question is: How do I search through the wp_postmeta for posts and display them?

  • The code you’re using will cause acf to save all of the fields to whatever post has the id of ‘300’. I’m not sure you’re using this correctly, to be honest I’m not sure where they values are being saved because you have 300 as a string and on a number. The values could be saved to the post with the ID of 300 or they could be saved in the options table with a prefix of “300-“. If they are saved to a post then there is no searching required. If they are save to the options table then searching is not possible.

    • nifel

    • November 16, 2018 at 7:56 pm

    The vaules are being saved in wp_postmeta like this:


    Do you think it’s possible to find them in a search?

  • I’m really not sure what you’re trying to accomplish. Searching is usually done on posts, filtered by meta. There isn’t anything in WP that just searches meta values. But like I said, I at this point I really don’t know what you’re trying to do.

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.