Solved

Wordpress Queries

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
WordPress website error - Unable to access website. 5 65
Word Press Contact Form 7 6 109
jQuery Toggle & Anchor Links 5 43
Share location on a web browser 4 11
WordPress is constantly evolving, and with each evolution appears to get better and better.  One of the big drawbacks prior to version 3 was that there was no way to be able to set up a custom menu from the backend. The Old Way Adding menus is…
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…

831 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