• Resolved senyoraangelica

    (@senyoraangelica)


    I have a custom post type, BOOKS. It has several custom fields, namely; TITLE, AUTHOR, GENRE, RATING. I need advice on how to fix my code below so that only books that have the search word in the custom fields; title, author, genre; WITH EXACTLY the rating specified in my search form, gets displayed in the results?

    I have made a custom search form; a text area that will search through the title, author, and genre; and a dropdown that will match the rating. The code in my params below only searches through the title, author, and genre. But I am now stumped in how to add the code for the rating.

    This is how I visually imagined it: (title OR author OR genre) AND rating.

    $params = array(
        'orderby' => $sortbooks,
        'limit' => 5,
        'search' => false,
        'where' => array(
            'relation' => 'OR',
              array(
                 'key' => 'title',
                 'value' => $searchvalue,
                 'compare' => 'LIKE'
              );
              array(
                 'key' => 'author',
                 'value' => $searchvalue,
                 'compare' => 'LIKE'
              );
              array(
                 'key' => 'genre',
                 'value' => $searchvalue,
                 'compare' => 'LIKE'
              );
    ),
            array(
            'relation' => 'AND',
              array(
                 'key' => 'rating',
                 'value' => $ratingvalue,
                 'compare' => '=',
                 'type' => 'NUMERIC'
              ));

    I would extremely appreciate your help and advice.

    http://wordpress.org/plugins/pods/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Scott Kingsley Clark

    (@sc0ttkclark)

    Try this:

    $params = array(
    	'orderby' => $sortbooks,
    	'limit' => 5,
    	'search' => false,
    	'where' => array(
    		'relation' => 'AND',
    		array(
    			'relation' => 'OR',
    			array(
    				'key' => 'title',
    				'value' => $searchvalue,
    				'compare' => 'LIKE'
    			),
    			array(
    				'key' => 'author',
    				'value' => $searchvalue,
    				'compare' => 'LIKE'
    			),
    			array(
    				'key' => 'genre',
    				'value' => $searchvalue,
    				'compare' => 'LIKE'
    			)
    		),
    		array(
    			'key' => 'rating',
    			'value' => $ratingvalue,
    			'compare' => '=',
    			'type' => 'NUMERIC'
    
    		)
    	)
    );
    Thread Starter senyoraangelica

    (@senyoraangelica)

    That worked perfectly! Thank you!!! You’re the best!!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Need advice on how I should fix my $params’ is closed to new replies.