Solved

Wordpress Queries

Posted on 2012-04-09
2
312 Views
Last Modified: 2012-04-13
Hey Wordpress guys,

I have the following working code to search for posts within my site based on meta_values.

$args = array(
                'cat' => $catid,
                'paged' => $paged,
                'showposts' => 9,
                'meta_query' => array(
                        array(
                                'value' => $searchtxt,
                                'compare' => 'LIKE'
                        )
                )
        );
        $wp_query->query($args);

Open in new window


Now I want to extent this to be able to find posts where $searchtxt either matches a value in wp_post_meta or the authors name in a single search query if it's at all possible.

I've done a bunch of searching, and the closest I've been able to find to what I'm trying to do is a tax_query with a relationship. Something like this (the below code is taken from the wordpress.org class reference).

$args = array(
	'tax_query' => array(
		'relation' => 'AND',
		array(
			'taxonomy' => 'movie_janner',
			'field' => 'slug',
			'terms' => array( 'action', 'commedy' )
		),
		array(
			'taxonomy' => 'actor',
			'field' => 'id',
			'terms' => array( 103, 115, 206 ),
			'operator' => 'NOT IN'
		)
	)
);
$query = new WP_Query( $args );

Open in new window


Is this at all possible?

Thanks.
0
Comment
Question by:jnbkze
2 Comments
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 500 total points
ID: 37826321
Yes, this is possible but you will have to modify your methods so that you are using SQL commands.  See the example here:

http://codex.wordpress.org/Custom_Queries#Keyword_Search_in_Plugin_Table

for code and let me know if you can follow it...
0
 
LVL 3

Author Closing Comment

by:jnbkze
ID: 37844004
Thanks for the answer. You pretty much confirmed what I suspected that I would have to write some custom sql. For the meantime, I've decided a simpler approach will be to simply store the author information in the post meta as well.

Thanks again.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

WordPress can be pretty daunting, especially for a beginner, so I thought it might be a good idea to write an article to show how easy it is to get started in WordPress and to design a custom theme.  The first step is to check with your hosting comp…
So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question