• Hello so I have this code and it works but not as I want. It searches by post id but it needs to be exactly the same. So it would show if I have post number 13 but if I have post number 131 it wont appear in results. I am doing auto filter. Just to make it more clear if I have posts with ID’s: 13, 131 and I write number 1 in search it needs to show both. Is there a function which would do it?

    $search = 13;
    $args = [
    'p' => $search,
    'post_type' => 'turai',
    'post_parent' => 0,
    'post_status' => 'publish',
    'posts_per_page' => $ppp,
    'paged' => 1,
    ];
    $loop = new WP_Query($args);
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    There is no WP function that will work that way on the ID field. You’d need to make your own SQL query using $wpdb methods. Alternately, you could use WP_Query class to form the bulk of your query, then use the “posts_where” filter to add the additional " AND `wp_posts.ID` LIKE %$search%" criteria to the WHERE clause.

Viewing 1 replies (of 1 total)
  • The topic ‘Search by post id (LIKE)’ is closed to new replies.