• Resolved Tadaki1989

    (@tadaki1989)


    Hi everybody,

    I created my own search form with some checkboxes which let the user restrict the search to post with certain categories, tags etc.
    I do this by adding arguments to the search string; it looks for example like this:

    (url)?s=xy&cat=178&post_type=post

    I’d like to do that also with certain custom fields my post have; how can I do that?

    1. is there something I can add to the string, so that the search is automatically restricted to a custom field value (like “&cf:year=2014”)?

    2. If not, how do I have to change “search.php” to read out the respective value of the search string and display only posts with this custom field value?

Viewing 1 replies (of 1 total)
  • Thread Starter Tadaki1989

    (@tadaki1989)

    Got it by myself; in the search.php, right before the loop, place something like this:

    <?php
    $var = $_GET['custom-field-name'];
    $posts = get_posts(array(
    	'numberposts'	=> -1,
    	'meta_key'		=> 'custom-field-name',
    	'meta_value'	=> $var
    ));
    ?>
Viewing 1 replies (of 1 total)
  • The topic ‘Search: Restrict by custom field value?’ is closed to new replies.