Home › Forums › Weaver Show Posts & Show Sliders › Is there a way to create a this category AND that category filter?
- This topic has 16 replies, 5 voices, and was last updated 10 years, 7 months ago by
caldcyn.
-
AuthorPosts
-
November 25, 2015 at 19:18 UTC - Views: 2 #18366
ldekay
ParticipantI’d like to be able to use multiple categories in an AND relationship to limit the number of categories I have to create.
We have several chapters in a parent organization and I’d like to display the News posts for all chapters on a General News page, but limit the News posts on a chapter’s page to just those posts pertaining to that chapter.
To limit the number of categories (which is already getting out of hand) I’d like to have a filter for Chapter1 that required News AND Chapter1 categories. Otherwise I’ll have to create separate ChapterXNews categories for each chapter.
Current show posts filter shows all posts categorized as News OR Chapter. e.g., http://whitesalmonevents.com/iafi/local-chapters/columbia-river-gorge-chapter/
November 25, 2015 at 20:07 UTC - Views: 1 #25060scrambler
ModeratorYou may be able to do that using a wordpress query (last option in the filter page), it will require finding out the proper syntax for the query, so searching the codex and WP forum
WP query: http://codex.wordpress.org/Class_Reference/WP_Query
forum: https://wordpress.org/support/topic/query-posts-belonging-to-2-categories
http://codex.wordpress.org/Function_Reference/WP_Query#Category_Parameters
Although Weaver says that it wont accept query using array () and that may be a problem
November 25, 2015 at 21:00 UTC #25061scrambler
ModeratorBy curiosity I checked if I could make it work without using arguments that require array.
I could not make it work with two categories, but I was able to make it work using a category and a tag.
So if you tag your news post with a news tag, then you can use the wp query filter option like below
tag=news & category_name=Chapter1
December 26, 2015 at 06:45 UTC #25062ldekay
ParticipantThat looks like it’s probably the best that can be done. Thanks
January 23, 2016 at 15:54 UTC - Views: 2 #25063LynR
ParticipantYou could also make a new Page with Page with Posts as the template. Then scroll down to Page with Posts Options (if you don’t see it open the options tab at the very top of your window to select it) and put in the Category slug for the appropriate Chapter (eg. chapter1) If you don’t want a category to appear on the main News page, put a minus sign on the category line (eg. -chapter1) on that page.
January 27, 2016 at 22:49 UTC - Views: 15 #25064caldcyn
ParticipantIn a standard WP_Query it supports syntax to filter on Category 1 AND Category 2 (intersection). Here’s the excerpt from http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters:
Display posts that have “all” of these categories:
$query = new WP_Query( array( 'category_name' => 'staff+news' ) );And you can test that this works if you pass this as a query param string in a URL:
http://{mysite}/all-articles/?category_name=cat1+cat2
It will only return posts that belong to both cat1 AND cat 2.
But for some reason this isn’t working in the show posts plugin (or for page with posts). I would think it would just pass this along directly to the query w/o additional processing?
Is this a bug?
I am trying to find a decent workaround and can’t. Because in one place I need to display cat1+cat2, and in another place I need to display cat1 MINUS cat2 (posts in cat1 but not also in cat2). Passing in cat1,-cat2 works for that. I tried using a tag for cat2, but you can’t do the exclude tag thru the plugin or pwp. And logically it doesn’t make sense for my cat1 to be a tag.
(I’ve been trying ways to solve my original problem from http://forum.weavertheme.com/discussion/13300/page-with-posts-not-showing-all-sticky-posts-when-paged#latest). The suggestion of having a separate pass using the plugin seemed promising, but the only way to do it is if I have a separate “Cat1Sticky”, “Cat2Sticky”, etc for each category. Where I really want Cat1, Cat2 and then either another cat Sticky or make Sticky a tag… So ultimately I need a first query that shows posts in Cat1 that are sticky, and a 2nd query that shows the rest of the posts in Cat1 that aren’t sticky.)
January 27, 2016 at 23:11 UTC - Views: 7 #25065scrambler
ModeratorIf I remember well, it is not possible with Show_post because it does not support WP query using an array, and that appeared to be required for what was requested.So as far as I can tell you either have to use category and tags to be able to do an AND in the selection, or do what I suggested in your other thread which is to use one sticky category for each category, so you use a combination of ADD and HIDE to select the proper postsJanuary 30, 2016 at 16:52 UTC - Views: 1 #25066caldcyn
ParticipantTh category_name query parameter doesn’t require an array. Just as you can pass a comma-separated list of category names in a string (“cat1, cat2”), you pass “cat1+cat2” as a string for that same query param.
January 30, 2016 at 19:51 UTC - Views: 1 #25067scrambler
ModeratorI am not a PHP specialist so…If there is a WP query that does the job without using array, then you should be able to use it in the WordPress query options at the bottom of the filter option page.But last time I tried, I did not find one.January 31, 2016 at 00:48 UTC - Views: 1 #25068Weaver
KeymasterJust trying to use cat1+cat2 in the Page with Posts template for Category does not work as an AND operator.
January 31, 2016 at 00:53 UTC #25069scrambler
ModeratorThat was my recollection. asking for all cat1 plus all cat2, is different from asking for posts that have both cat1&cat2
February 1, 2016 at 18:38 UTC - Views: 2 #25070caldcyn
ParticipantTo ask for posts that have cat1 or cat2 (union), you use the comma (“cat1, cat2”) with the category slugs. To ask for posts that have cat1 AND cat2 (intersection), you use the plus (“cat1+cat2”). You can try it out using a url parameter for example on an archive page. Here’s an example: http://www.yetanothermomblog.com/topics/kids-crafts+gardening/. It returns the intersection of those categories. (I can’t use ?category_name=kids-crafts+gardening here because of the rewrite rules, but it’s doing the same query behind the scenes.)
It’s the same behavior with tags. For example http://www.yetanothermomblog.com/?tag=coloring+freebie returns only the posts tagged with coloring AND freebie.February 1, 2016 at 18:52 UTC - Views: 1 #25071scrambler
ModeratorAs I mentioned before. if you know a wordpress query that does not use array that actually works to do the job, then you can use it in the wp query option section of show_posts filter page.
February 1, 2016 at 19:31 UTC - Views: 1 #25072Weaver
KeymasterThe WP_Query value used by the filter is ‘cat’ which only accepts commas. AND requires ‘category__and’ which uses an array value, which Weaver’s category filter does not handle.
The Weaver filters for category have nothing at all to do with the URLs as you put in your examples.
See: https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters
February 1, 2016 at 22:07 UTC #25073caldcyn
Participantfilter ‘cat’ uses category ids and not category slugs. But your UI takes slugs. So I assumed you were using category_name behind the scenes as the query parameter. So are you translating the slugs to ids?
If you go to the wordpress page you reference above, there are 2 examples of using category_name – one for comma and one for plus. But if you are using cat with ids, then that explains my confusion.February 1, 2016 at 23:14 UTC #25074Weaver
KeymasterWhen the category filter for Weaver was implemented, it seemed (and still does) more critical to have the “-” (not) operator available as an option – it was way more requested than AND. So the easiest way to implement that was with ‘cat’ (and ‘tag_id’). So internally, the slugs are in fact converted to IDs.
-
AuthorPosts
- You must be logged in to reply to this topic.

