How to query listings in Sabai Directory plugin? - php

I'm looking for a way to query listings in PHP using Sabai Directory plugin. In my code, I extract the keywords from $_SERVER['REQUEST_URI'] and then intend to use them to find matching listings. Now, the problem is I need a way to assign those keywords to my listings in the first place. I tried 2 approaches:
Categories. It seems that Sabai does not support core WP categories (does it?), but has its own version. So if you create a Category, Sabai creates a page with a permalink for it. However, my categories are very trivial, they just have a label and a value with no content or no media; I don't want users to see category pages (e.g. /directory/categories/chocolate), it makes no sense.
Is there a way NOT to create a separate page for each category?
How do you query listings by multiple categories? Would this work: [sabai-directory category="chocolate,arizona,phoenix"], with category separated by comma?
Custom fields. I couldn't figure out categories by myself, so I created custom fields to simulate core WP categories. But the problem is I can't find a way to query listings by these custom fields. So if I need field_state field to be set to arizona or massachusetts, how do I limit my listings to either of those values?
Is there a way to specify custom fields in shortcodes?
Is there an API in Sabai that I can use to query listings directly? What would the post type be? What would the query look like? (There is no info on this in the docs)
On the same topic, once you query the listings, how do you display the contents for a single listing? I've tried [sabai-directory-listing id="?"] shortcode, but I don't understand where you get the id from: $post->id doesn't work.
Please let me know if you have any info

Related

WordPress: Replace custom URL structure for posts in specific category

In Dashboard->Settings, I have Custom Structure for my Posts set to myurl.com/blog/%postname%/
This currently works as intended for all individual Posts, but for Posts with a specific category (in this case, "testimonials"), I would like to change it to be: myurl.com/testimonials/the-post-slug
I tried using this plugin: https://wordpress.org/plugins/custom-permalinks/, and while this works great for setting a custom URL for the top-level Category page, it seems like I would still need to manually set each the custom URL structure for each individual Post, which is not ideal.
I'd like to accomplish this without needing to register a new Post type, as there are currently a lot of Posts in the "testimonials" category and I do not want to need to worry about new loop templates or anything like that.

How to display two taxonomy terms on multi taxonomy category page in WordPress

I am currently trying to extend my sites beyond the typical category -> posts structure and get more specific with pages that target multiple taxonomies. Basically here is what I want to do.
I have a Custom Post Type set up, and each custom post in in multiple taxonomies and can have multiple values in each taxonomy. So CPT1 can have Tax1 values of Blue and Red and Tax2 values of Widgets and Fidgets.
I currently have it working where pages like site.com/tax1/red/widgets/ works as a valid URL and it returns the correct set of posts within the CPT. Awesome! That code is here:
//trying to create pages for eg /tax1/tax1value/tax2value/
function custom_rewrite_rules() {
add_rewrite_rule('^tax1/(.)/(.)?', 'index.php?
tax1=$matches[1]&tax2=$matches[2]', 'top');
}
add_action('init', 'custom_rewrite_rules');
Now I am running into an issue that is currently above my skill level. I'm trying to:
Make the , , and on the page reflect both values (eg "red" and "widgets") so that the will say "Red Widgets". Currently, it just says "widgets".
Things I notice and have tried:
The page site.com/tax1/red/widgets/ is using the taxonomy.php template page, but seems to be pulling the tax2 . So instead of having a class of tax-tax1 within the tag, I get tax2 (which in this case is actually tag, so it shows up as instead of like on regular tax1 value pages like site.com/tax1/value-here/)
I've tried pulling the terms using but that a) doesn't do anything and b) in my investigations found that this is really for posts, not a combo category page like this.
So, the specific questions:
Any links to resources on getting the page site.com/tax1/red/widgets/ to use the taxonomy head/body instead of the tag body like currently?
Any links to resources on modifying the query being used so I can display both taxonomy values being used ("red" and "widgets") and not just pull the dominant one (tags in this case)
Thanks so much in advance.

Wordpress - Make category.php list posts from subcategories as well

I'm building a blog where three people will be writing, but they will have a separate section on the site. The structure is built upon categories and looks like this:
User one
Clothes
Fashion
Life
User two
Family
Life
User three
Family
Friends
Life
I've set all three users as writers and used the plugin Restrict Categories in order to lock their categories to the sub-categories the matching each top level category.
Now here comes the question, if I visit http://site.example/category/user-one/ I want to have a listing of all the posts, including the sub-categories since there will be no actual content in the top level category that you are browsing.
I've tried making this using filters bound to pre_get_posts but I still can't get it to work. Does anyone else here have any ideas?
I've also given some though into actually creating a multisite network for the purpose, but I then realized it will be hard to fetch posts from all the networks at once.
Thanks in advance, Jonathan
#Jonathan: Not sure if I am misinterpreting what you are hoping to achieve, but given that each author will already have their own 'author' page which lists all their posts (if your theme includes this or something you could create or customise), there may not really be a need for Users 1-3 to be their own category?
Going back to your question, for listing subcategories, perhaps https://wordpress.stackexchange.com/questions/13485/list-all-subcategories-from-category might be of some help.
As for listing posts, to keep things simple, I reckon you might be able to use e.g. get_posts (http://codex.wordpress.org/Template_Tags/get_posts) and build custom arguments, perhaps in a loop if you prefer to use one instead of slug/id specific category templates.
http://codex.wordpress.org/Category_Templates
If it's any help, Bainternet actually created a plugin that makes life a little easier to define category templates: http://wordpress.org/plugins/custom-category-template/

wordpress custom search for post under selected category

Hi I want to create a custom post search under a particular category. How can I create that.
How to create a custom where condition related to that particular category?
You should try hijacking the search results (in search.php) if you have a certain query.
Meaning:
if a category (ID) is sent (perhaps as catID) by the search form together with the usual s variable, do a new query_posts('s=$s&paged...&cat=$catID');.
else just let the internal search take care of the results.

In Drupal 6, is there a way to take a custom field from the latest post to a taxonomy term, and display it in a view?

The title for this question pretty much sums up what I'm asking.
I've got a list of taxonomy terms, and I'm using a view to display the latest post to each one. I'd like to also display a custom field set up in CCK just under this.
Currently, I'm just using "date updated" of the taxonomy term itself which was easy to set up in views. I'd like to drill a little deeper and get the custom "event date" field I've added to the content type last posted to the taxonomy term I'm "viewing".
I've got a feeling I'm going to have to write my own database query for this.
If (I can avoid that){
How do I set up such a view?
}
Else{
What's the best practice for including lower level database queries alongside views?
}
what about using row style instead of node style for your view, and building the desired look of the view with a custom module? this would let you send the fields you want to the page and then theme them however you wish.
See this issue on drupal.org: http://drupal.org/node/193187. Technically, SQL does not allow you do a grouped query and set a limit per group. It would be possible to execute a grouped query and only display the first of each group on the theme level. However, depending on the number of nodes, that might not perform too well - I'm not sure.

Categories