Solved

Wordpress Queries

Posted on 2012-04-09
2
309 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Who says nothing in life is free? WordPress.com is a freebie. WordPress.org's downloadable publishing platform is free. Heck, even WordPressMU is free. WordPress is an open source project, which means it can be used on any personal or commerc…
WordPress has made it easy to create scalable sites based on their powerful CMS, but as great as WordPress is, there are some SEO issues that haven’t been addressed out of the box.  Fortunately these problems can be solved with a few plugins.  The f…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

747 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now