Solved

Wordpress Queries

Posted on 2012-04-09
2
315 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Now that you've installed WordPress 2.9 (http://www.experts-exchange.com/articles/Web_Development/Blogs/WordPress/WordPress-2-9-What-to-Expect-When-Upgrading-to-WordPress-2-9.html?) on your site, you need to install some plugins to get the most out …
How to create your own WordPress Theme Before I begin with the theme design tutorial, I would like to give you the basics of what is required to make a WordPress Theme. The most basic WordPress theme only requires 2 files: a style.css file and an…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

738 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