WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We're working on a database with personal data from different sportsmen such as name, height, weight, etc.

We've managed to build a detailed filter through query_posts.

Every filter field is working as expected except for the text input field that we use to filter the sportsman by name. The problem is that when we are looking for the name of a single sportsman, the form just allows us to find the sportsmen by its exact name.

For example: If we are looking for a sportsman called John Doe, we would need to write the exact name of the post title ('John Doe'). Instead, we would like to be able to have results just typing 'John' or 'Doe'.

Our query_posts filter looks like this:

query_posts( array(
    'name' => $sportsman_name,
    'post_type' => 'db',
    'posts_per_page' => 100,
    'paged' => $paged,
    'category_name' => $sport,
    'meta_query' => array(

) );

That's how the form field looks like:

<input name="sportsman" type="text">

And that's how we create the string to filter the results in the query_posts:

$sportsman = $_GET["sportsman"];

    if($sportsman == ''){
        $sportsman_name = null;
        $sportsman_name = $sportsman;
share|improve this question

First, use WP_query instead of query_posts.

$my_query = new WP_query( args... );
if ( $my_query->have_posts() ) {
    $sportsman = ...

Second, to not filter by exact values you might use regular expressions (e.g., set the name within the array to "/^.*{$sportsman_name}.*$/"). Id did not test that.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.