Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Custom field related query WordPress

  • SOLVED

I am looking to replicate the query from this - http://wordpress.org/extend/plugins/query-custom-fields/. The plugin works great, but it has a bug which strips out all your meta titles and it's killing my SEO.

I need to be able to create search URLS that will look for posts that have certain values in certain custom fields. ie the custom field is called edit_cat and the value is boots. Result is

http://wordpress.org/extend/plugins/query-custom-fields/
(which displays like a normal search).

i don't need the script to output the link or anything like that, i can edit it manually, just need for it to understand it.

I found this other related WP Questions post which is similar but I can't get my head around how to make it work. http://wpquestions.com/question/show/id/538

I also need for it be able to be able to accepts multiple arguments in the search - ie http://yoursite.com/category/special/?price-min=500&price-max=2000&orderby=price

Answers (2)

2011-05-06

Julian Lannigan answers:

I created a plugin for what you are asking. It will soon be in the plugin directory. I will be developing this plugin further.

But you can download here: [[LINK href="http://jlconsulting.co/plugins/custom-query-fields.zip"]]http://jlconsulting.co/plugins/custom-query-fields.zip[[/LINK]]

You can see an example of the plugin working here:

[[LINK href="http://testwp.jlconsulting.co/?price_min=300&orderby=price"]]http://testwp.jlconsulting.co/?price_min=300&orderby=price[[/LINK]]
[[LINK href="http://testwp.jlconsulting.co/?price_min=300"]]http://testwp.jlconsulting.co/?price_min=300[[/LINK]]
[[LINK href="http://testwp.jlconsulting.co/?price=650"]]http://testwp.jlconsulting.co/?price=650[[/LINK]]
[[LINK href="http://testwp.jlconsulting.co/?price_min=500&price_max=1000"]]http://testwp.jlconsulting.co/?price_min=500&price_max=1000[[/LINK]]
[[LINK href="http://testwp.jlconsulting.co/?price_min=500&price_max=1000&orderby=price"]]http://testwp.jlconsulting.co/?price_min=500&price_max=1000&orderby=price[[/LINK]]


kateM82 comments:

Hi Julian,

Thanks so much for the link, hand coincidence!

I can't quite get it to work though.

I have installed it. And added the below to the custom functions php (i use thesis).

`
/**** reader edit register custom fields***/

register_custom_queryable_field('edit_cat' );
register_custom_queryable_field( 'edit_brand');
register_custom_queryable_field( 'edit_price', array('dataType'=>'numeric', 'order'=>'ASC'));' `

The search i tried was this -
http://dropdeadgorgeousdaily.com/?edit_cat=jackets
http://dropdeadgorgeousdaily.com/?edit_cat=bag

and it just brought up the homepage?

What should I do?


Julian Lannigan comments:

What version is your blog at? With this plugin I used the "meta_query" option as opposed to the meta_key and meta_value options.


Julian Lannigan comments:

I updated the plugin.
[[LINK href="http://jlconsulting.co/plugins/custom-query-fields.zip"]]http://jlconsulting.co/plugins/custom-query-fields.zip[[/LINK]]


kateM82 comments:

Still no joy, I am using 3.0.1

The other plugin did work, not sure what they were using, it just had the horrible side effect of wiping out the title tags and was no longer being maintained.

This is really urgent... anyone???


Julian Lannigan comments:

I am changing the plugin to work with your version.


kateM82 comments:

Hi Julian,

Also so you know this breaks WP touch too, the error I get is on lines 40 and 69 of custom-fields-query.php "invalid argument foreach()"


kateM82 comments:

Hi Julian,

I updated to the latest version of Wordpress and it's still not working. :(


Julian Lannigan comments:

Try to update the plugin now, I have tested it in my 3.0 environment.

[[LINK href="http://testwp.jlconsulting.co/3.0/?price_min=300"]]http://testwp.jlconsulting.co/3.0/?price_min=300[[/LINK]]


Julian Lannigan comments:

Any luck?


kateM82 comments:

Sorry Julian, where is the update?


Julian Lannigan comments:

[[LINK href="http://wordpress.org/extend/plugins/custom-query-fields/"]]http://wordpress.org/extend/plugins/custom-query-fields/[[/LINK]]

it is on the repository, so you can add it from wordpress.


kateM82 comments:

Sorry silly, me, didn't realise it was in there now, will give it a whirl! :)


Julian Lannigan comments:

cool deal, just let me know how it goes.


kateM82 comments:

Still no good. darn it. I do have a lot of plugins though so it might be one of them interfering. Such a shame because the other one by Scribu did work, but broke something else, so it must be possible even with ALL the plugins.


Julian Lannigan comments:

Right now, I have setup the plugin to run on the first query it comes across. On your home page it looks like you may have many queries running. So I added enable/disable functions in the plugin so you can enable the plugin for an external query. If you have a get_posts type of function call, I suggest placing CustomQueryFields::enable(); right before it.

You notice the following link is returning no results:
[[LINK href="http://dropdeadgorgeousdaily.com/category/daily/daily-looks/?edit_cat=jackets"]]http://dropdeadgorgeousdaily.com/category/daily/daily-looks/?edit_cat=jackets[[/LINK]]

Whereas, this link does:
[[LINK href="http://dropdeadgorgeousdaily.com/category/daily/daily-looks/"]]http://dropdeadgorgeousdaily.com/category/daily/daily-looks/[[/LINK]]

Do you have some example posts on your site that has particular custom posts?


kateM82 comments:

By custom posts do you mean the posts that have the custom field I want to search?

It's mostly for the affiliate store I am redoing at the moment.


http://dropdeadgorgeousdaily.com/dshop-online-shopping/ (here is the landing page - work in progress).

All items that feed into this are under the category - http://dropdeadgorgeousdaily.com/category/store-dshop/

The custom fields used to sort these are dshop_cat dshop_store dshop_brand & dshop_price (the edit_cat ones are for another section too)

Does that help??






kateM82 comments:

And where do I place this?? CustomQueryFields::enable();


Julian Lannigan comments:

Notice this works: [[LINK href="http://dropdeadgorgeousdaily.com/?s=Fashion%20Artiste&cat=5121&edit_cat=jacket"]]http://dropdeadgorgeousdaily.com/?s=Fashion%20Artiste&cat=5121&edit_cat=jacket[[/LINK]]

Can you post the template code you are using to display [[LINK href="http://dropdeadgorgeousdaily.com/dshop-online-shopping/"]]http://dropdeadgorgeousdaily.com/dshop-online-shopping/[[/LINK]]?

But the CustomQueryFields::enable(); should only be used if you are using external queries you want the custom fields applied to the query. But if you have one you place the line just before the query.


kateM82 comments:

How interesting, so it works when it's piggy backing on the styling of an existing search query? that's actually workable for me!

Still no idea what to do with is?

CustomQueryFields::enable();

But probably don't need it now.


Why do you need the landing page template code? Surely it's more to do with the search template??


Julian Lannigan comments:

So by default when you request a page from wordpress, there is a "main" query that is constructed and run. The plugin effects that query by default. [[LINK href="http://codex.wordpress.org/Query_Overview"]]Query Overview[[/LINK]]

The CustomQueryFields::enable(); is used if you have a "get_posts()" function in your template file. Thats what I call an "external" query.

But, if it works for you then I would use that.


Julian Lannigan comments:

The only reason I was asking for the template code was so that I could see what other queries you were running on that page. And so I could show you how to use the enable function.


kateM82 comments:

Thanks for your help Julian! I've given the plugin a 5 star rating :)

2011-05-08

Just Me answers:

Hi,

not sure how experienced you are with coding but did you read this article? http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query
It has custom field examples as well.


kateM82 comments:

I want it to act like a search, not like a loop, I've used this before, but it's not what I need at this time. Thanks.


Just Me comments:

Did you try to load the plugin you mention, after the meta tags have been loaded?