Querying Two Wordpress Categories via URL - wordpress

I have posts that are assigned to two categories let's say cars and paints. I'm trying to only get posts that are in both, the following code http://example.com/category/cars+paints is supposed to work according to this article but it doesn't and I get a page saying The requested document was not found on this server. When I try http://exapmle.com/category/cars,paints it works but it gives me too many posts.
It seems that & is supposed to work as well, I tried http://exapmle.com/category/cars&paints and http://exapmle.com/category/?cat=cars&cat=paints but this doesn't either work, I don't know if I have the syntax wrong.
When I try http://exapmle.com/?cat=1&cat=2 using the category IDs it directs to a page like this http://exapmle.com/category/paints with the last parameter corresponding to the last number entered in the URL.
Does anyone know why it's not working and what I can do to get it to work, thanks in advance.

Changing the + to a space %20 seems to be working for me
Example:
http://example.com/category/cars%20paints

Related

Woocommerce Underscore is added to some product URLs

Got an unusual problem that started recently and wonder if anyone has any ideas why it's happening and how to stop it.
Some of my products are getting an underscore added to the url when selected which, naturally, results in a 404 error. It's consistent - either an underscore gets added or it doesn't. It doesn't seem to be related to the GUID or the post_name in the wp_posts table. It also doesn't matter if you call it using the URL or the post ID so the following:-
Bad index.php?page_id=1075707 the-john-rutter-christmas-piano-album-2 https://website-name.com/product/the-john-rutter-christmas-piano-album-2/
Good index.php?page_id=1087442 the-john-rutter-piano-album https://website-name.com/product/the-john-rutter-piano-album/
Bad index.php?page_id=1159681 parable-for-harpsichord https://website-name.com/product/parable-for-harpsichord/
Good index.php?page_id=1159684 jesu-meine-freude-2 https://website-name.com/product/jesu-meine-freude-2/
Bad here meaning that the URL appears with an underscore such as
https://website-name.com/product/parable-for-harpsichord_/
I've also tried this with every single plugin, except WooCommerce, de-activated and with my functions.php disabled. No difference.
I've tried using the URLs as given above, C&P or typed in manually and by directly referencing the post ID (as shown).
This has only recently started and I'm at a bit of a loss here. I don't know how widespread this problem is either since I've over 120,000 products and can't check them all by hand. Fortunately, this isn't live yet.
Any suggestions or ideas here would help me.
There appears to be a hidden character at the end of the post_name field. Deleting and recreating the field got rid of the problem.

How to choose the last member of an array in a datalayer?

Then I would like to get the smallest child Category of a post that belongs lots of categories (via the datalayer pageCategory used plugin called GTM4WP by Duracell Tomi).
How can I do that?
I had already known to get the biggest category: pageCategory.1
Already tried pageCategory.10 or pageCategory.length-1 but didn't work. I'm not really familiar with Javascript. Please guide me
You need to use the length of the array, but with a different syntax:
pageCategory[pageCategory.length-1]

WooCommerce Rest API - Product category filter not working

I have created an app which is displaying some products using the WooCommerce Rest API.
I have applied a few filters and everything was looking good until I tried to apply a filter for the category
http://foo/wc-api/v3/products?filter[limit]=15&filter[category]=some-category&oauth_consumer_key=ck_xx&oauth_nonce=xx&oauth_signature_method=HMAC-SHA1&oauth_timestamp=xx&oauth_version=1.0&filter%5Blimit%5D=15&filter%5Bcategory%5D=antioxidants&oauth_signature=xx%3D
Now I get the message
DENIED - The requested resource requires user authentication. (XHR): GET ...
Any ideas why that is?
Found the answer (at least it's working for me)
You need to make the filter[category] the first parameter in your query string.
I'll let the guys know about this too.

Wordpress : Url Rewrite

I am trying to rewrite a url in wordpress so that I can serve up dynamic content based on variables that are passed. I have a plug in that needs variable data passed into it. Currently I have:
http://xyzsite.com/page/?var1=something
this works fine and passes in a $_GET var. So my next step is to clean up the variable so that it looks like
http://xyzsite.com/page/something
I have done a few google searches and come accross some site that looked promising but I cannot get any of them to work. From what I have read, i need to use
add_rewrite_tag and add_rewrite_rule
After reading through the articles I have added this to my functions.php page:
add_rewrite_tag('%var1%','([^&]+)');
add_rewrite_rule('^page/([^&]+)/?','index.php?p=1141&var1=$matches[1]','top');
when i navigate to the page http://xyzsite.com/page/something i get a 404 error. When i navigate the to http://xyzsite.com/page/?var1=something it is still working fine. So it looks as if my rewrite is not registering or working correctly.
Can someone help me to achieve the above rewrite. FYI my permalink settings is set to post name if that matters at all. Thank you.
I̶'̶m̶ ̶n̶o̶t̶ ̶a̶ ̶r̶e̶g̶e̶x̶ ̶p̶r̶o̶,̶ ̶b̶u̶t̶ ̶I̶ ̶s̶u̶s̶p̶e̶c̶t̶ ̶a̶n̶ ̶i̶s̶s̶u̶e̶ ̶i̶n̶ ̶y̶o̶u̶r̶ ̶r̶e̶w̶r̶i̶t̶e̶ ̶r̶u̶l̶e̶:̶
a̶d̶d̶_̶r̶e̶w̶r̶i̶t̶e̶_̶r̶u̶l̶e̶(̶'̶^̶p̶a̶g̶e̶/̶(̶[̶^̶&̶]̶+̶)̶/̶?̶'̶,̶'̶i̶n̶d̶e̶x̶.̶p̶h̶p̶?̶p̶=̶1̶1̶4̶1̶&̶v̶a̶r̶1̶=̶$̶m̶a̶t̶c̶h̶e̶s̶[̶1̶]̶'̶,̶'̶t̶o̶p̶'̶)̶;̶
̶
̶N̶o̶t̶e̶ ̶t̶h̶e̶ ̶/̶?̶ ̶y̶o̶u̶'̶v̶e̶ ̶a̶d̶d̶e̶d̶ ̶a̶t̶ ̶t̶h̶e̶ ̶e̶n̶d̶.̶ ̶T̶h̶u̶s̶ ̶y̶o̶u̶ ̶s̶h̶o̶u̶l̶d̶ ̶a̶c̶c̶e̶s̶s̶ ̶y̶o̶u̶r̶ ̶p̶a̶g̶e̶ ̶w̶i̶t̶h̶ ̶h̶t̶t̶p̶:̶/̶/̶x̶y̶z̶s̶i̶t̶e̶.̶c̶o̶m̶/̶p̶a̶g̶e̶/̶s̶o̶m̶e̶t̶h̶i̶n̶g̶/̶?̶ ̶a̶n̶d̶ ̶n̶o̶t̶ ̶x̶y̶z̶s̶i̶t̶e̶.̶c̶o̶m̶/̶p̶a̶g̶e̶/̶s̶o̶m̶e̶t̶h̶i̶n̶g̶.̶ ̶H̶a̶v̶e̶ ̶y̶o̶u̶ ̶t̶r̶i̶e̶d̶ ̶i̶f̶ ̶t̶h̶a̶t̶ ̶w̶o̶r̶k̶s̶?̶
The stroked out text above is wrong, as Gustavo Straube pointed out in the comments. Please disregard that proposed solution.
My only last advice is to try adding a flush_rules(); after your last add_rewrite_rule, as stated in http://codex.wordpress.org/Rewrite_API/flush_rules.
Note that you should be accessing your query vars with get_query_var('var_name') instead of trying to access $_GET directly.

How to OR solr term facets via the search URL in Drupal 7 site?

I have a Drupal 7 website that is running apachesolr search and is using faceting through the facetapi module.
When I use the facets to narrow my searches, everything works perfectly and I can see the filters being added to the search URL, so I can copy them as links (ready-made narrowed searches) elsewhere on the site.
Here is an example of how the apachesolr URL looks after I select several facets/filters:
search_url/search_keyword?f[0]=im_field_tag_term1%3A1&f[1]=im_field_tag_term2%3A100
Where the 'search_keyword' portion is the text I'm searching for and the '%3A' is just the url encoded ':' (colon).
Knowing this format, I can create any number of ready-made searches by creating the correct format for the URL. Perfect!
However, these filters are always ANDed, the same way they are when using the facet interface. Does anyone know if there is a syntax I can use, specifically in the search URL, to OR my filters/facets? Meaning, to make it such that the result is all entries that contains EITHER of the two filters?
Thanks in advance for any help or pointers in the right direction!
New edit:
I do know how to OR terms within the same vocabulary through the URL, I'm just wondering how to do it for terms in different vocabularies. ;-)
You can write a filter query that looks like:
fq=field1:value1 OR field2:value2
Alternatively you can use localparams to specify the query operator:
fq={!q.op=OR}field1:value1 field2:value2
As far as I know, there's not any easier way to do this. There is, in fact, an rather old bug asking for a way to OR the fq parameters...
I finally found a way to do this in Drupal
Enable the fq parameter setting.
Go to admin/config/search/apachesolr/[your_search_page]/core_search/edit or just navigate to the settings of the search page you're trying to modify
Check the 'Allow user input using the URL' setting
URL Syntax
Add the following at the end of the URL: ?fq=tid:(16 OR 38), where 16 and 38 are the term ids

Resources