Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
  • #6028

    I’m trying to post a solution on how to sort and display listings based on a custom field created with FormBuilder.

    CloudFare blocks me as it parses my solution.

    Any way to post the actual code and solution?
    The backquotes from the code button doesn’t do the trick.



    I replaced all dollar sines with @, single quotes with * and double quotes with ~ in order to be able to post the solution.

    <b>If anyone can help with this topic – please help.</b>
    Even if the custom search feature isn*t there now we can still make sense out of it, right?

    <b>How to display listings based on a custom field?</b>

    For starters, with the builder we*ll make a select field with 3 entries.
    We name the select field something unique: gr_select_program
    The values are: short,long,extended.

    How to search for Listings that have the long program?
    We need to find in the database the string ~gr_select_program~:~long~

    So that translates into this query:
    SELECT post_id FROM *wp_bepro_listings_form* WHERE form_values like *%gr_select_program~:~lung%*;
    In worpress code that translates as

    $my_custom_lists = $wpdb->get_results(~SELECT post_id FROM *WPTABLEPREFIX_bepro_listings_form* WHERE form_values like *%[email protected]_search.~%*~, ARRAY_N);

    Be careful to change:
    1. WPTABLEPREFIX to your actual prefix – the bepro constant for this table doesn*t work for me at this time so I just hardcoded the table name
    2. Put the table name in backquotes instead of single quote – that*s the left-most key under Esc.

    which results in a 2 dimention numerically indexed array, thus echo @my_custom_lists[0][0]; would output the first post_id (if any!)

    Great – now we have the IDs of all the Listings that have an unique custom field value.

    Now for the second part – displaying the results.
    In the file bepro_listings_frontend.php [from the listing plugin, not the formBuilder] we have the function display_listings which will display the listings based on shortcode.

    To the extract(shortcode add one more case to solve:
    *custom_search* => @_REQUEST[*custom_search*],

    Now we have our own custom_search shortcut field.
    just a few more rows in the page*s code you*ll see this comment:
    //make presumption to randomize featured listings

    just above it add our processing of the shortcode

    // deal with custom search
     @my_custom_lists = @wpdb->get_results(~SELECT post_id FROM *WP_PREFIX_bepro_listings_form* WHERE form_values like *%[email protected]_search.~%*~, ARRAY_N);
     @l_ids=**; // whatever l_ids we have selected in the shortcode is now gone
      foreach (@my_custom_lists[0] as @v_post){@[email protected]_post.*,*;}
      @l_ids=rtrim(@l_ids, ~,~); //delete the last added coma
     }else{@l_ids=*4702*;} // exception to be treated if no rows are found - I just put a known field ftm

    Don*t forget to change WP_PREFIX with your own prefix
    Don*t forget to put this table name in back-quotes instead of single quotes.

    If all is done correctly – we now have a functional shortcode for our special fields. Write the shortcode, inside your wp page, like this:
    [display_listings l_ids= *4269* custom_search=*gr_select_program___long*]

    You must enter something for l_ids – it will be overwritten.
    Mark that I have replaced the ~:~ with 3 underscores which makes it more clean to understand the shortcode [underscore is mysql wildcard for single character].

    That*s it. We are able to display a list of our custom entries. Of course we can now combine this with origami field and bl_form_id field to sort our entries.

    Anyone care to extend this functionality to the actual search function?

    • This reply was modified 7 years, 7 months ago by Cosmin.


    Thanks for sharing.

    You can definitely create an addon which does this. You can alter/add to the search query using wordpress action hooks. We talk about this here

    Hopefully, a few members from the community will be willing to contribute to this evolution!
    BePro Software Team


    I’ve never build a wp plugin and as much as I would like to do this I’m under development and behind my work so any quick fix would do to meet the deadline.

    Making a plugin out of this solution involves also a great deal of testing.
    If anyone has the spare time – pluginise away ^_^


    Completely understand 🙂

    BePro Software Team

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.