Wordpress get_posts if keyword exists in title, content or tag

admin

Administrator
Staff member
I am using get_posts to get a list of posts that match a search keyword, the problem is that I the
Code:
get_posts
's
Code:
s
<a href="https://codex.wordpress.org/Class_Reference/WP_Query#Search_Parameter">parameter</a> does not search tags by default and using
Code:
tag_slug__in
will not work if the keyword is found in the title and not in a tag.

The conditions of my search would be:

<ol>
<li>Return post if keyword exists in Title</li>
<li>Return post if keyword exists in Content</li>
<li>Return post if keyword is a tag associated with the post.</li>
</ol>

Any ideas would be fantastic. I tried the "Search Everything" plugin, but that only seems to work on WordPress' default Search Feature.

Code below is a simplified version of what I have attempted, not this does not satisfy all 3 criteria.

Code:
&lt;?php

/* Set global query parameters */
$image_args = array(
    'posts_per_page' =&gt; (isset($_GET['show_all']) &amp;&amp; $_GET['show_all'] == 'true')? 100000 : 20,
    'post_type' =&gt; 'attachment',
    'post_mime_type' =&gt; array('image/jpeg', 'image/png'),
    'meta_key' =&gt; 'language',
    'meta_value' =&gt; "(^".$languages."$|\"".$languages."\"\;)",
    'meta_compare' =&gt; 'REGEXP',
    'tax_query' =&gt; array(
        'relation' =&gt; 'AND',
        array(
            'taxonomy' =&gt; 'media_category',
            'field' =&gt; 'term_id',
            'terms' =&gt; array($gallery_filter, $hotel-&gt;term_id),
            'operator' =&gt; 'AND',
        ),
    ),
);

/* If page numbert given, add offet */
if(!empty($page_no))
    $images_args['offset'] = 20*((int)$page_no-1);


/* If search term submitted, add it to the s parameter */
if(isset($_GET['search'])){
    $image_args['tag_slug__in' = explode(" ", $_GET['search']);
    $image_args['s'] = urldecode($_GET['search_term']);
}