Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Wordpress Queries

Posted on 2012-04-09
2
Medium Priority
?
319 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 1500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

How to install BuddyPress on your self-hosted WordPress site It’s been called everything from “social networking in a box” to “Facebook without the terms of service,” but until Feb. 16, BuddyPress was a relatively unknown outside the WordPress MU…
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…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
Suggested Courses

782 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