first: Thank you for all the great new features!
Is it possible in a WP query that the LIKE operator finds only posts with the search text at the beginning?
I have read in another thread here in the forum, that the looper provider query string does not support regex - is that right?
Thanks for writing in! You can use an argument something like this:
$search_text = 'your_search_text'; // Replace with your actual search text $args = array( 'post_type' => 'post', // Replace 'post' with your custom post type if needed 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'post_title', // Replace with the actual post title meta key 'value' => $search_text, 'compare' => 'LIKE', ), array( 'key' => 'post_content', // Replace with the actual post content meta key 'value' => $search_text, 'compare' => 'LIKE', ), ), );
I have tried this already, it brings me all results where search_text is somewhere in the fields.
I need to find the results where search_text stands only at the beginning of the fields.
In MySQL I would do this:
SELECT * FROM table WHERE field LIKE “search_text%”
Is this possible?
That is possible if you use the ^ in front of the key you are searching for. And you also need to use REGEXP as shown in the following thread.
Please remember that the above code will work if copied as it is and don’t conflict with any existing style.
Please note that the code provided serves only as a guide to help you get started custom-coding on your own if there’s no option offered in our theme or the products we bundle.
We really do not provide support for custom codes, which means we can’t fix it in case it conflicts with something on your site, nor will we enhance it. Further customization should be directed to a third-party developer or you can avail of One, where we answer the questions beyond normal theme support.
Thank you so much!
Using CS Loopers and WP Query is becoming more and more exciting!
Glad that we are able to help you.