0

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:

  1. 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?
  2. 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

  • I don't have an answer, but did you ever figure this out? I can't find any info on how to query a listing in Sabai Directory, since it doesn't operate like a normal wordpress custom post type or taxonomy. – LBF May 12 '17 at 18:44
  • @LBF You can use shortcodes with the filter parameter, as the author suggested, but it didn't quite work for me. You should ask on the plugin's page for more info specific to your situation. . – Alex May 12 '17 at 18:58
0

@lbf you can try something like this, and work from here.

$results = get_posts( array(
        'post_type'        => 'wpbdp_listing',
        'post_status'      => 'publish',
        'numberposts'      => 10,
        'order'            => 'ASC',
        'orderby'          => 'name',
        'suppress_filters' => false
));

You also, @Alex. Oh, wait… ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.