Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #6029
    Cosmin
    Member

    Salut.

    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 *%~.@custom_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
    if(!empty(@custom_search)){
     @my_custom_lists = @wpdb->get_results(~SELECT post_id FROM *WP_PREFIX_bepro_listings_form* WHERE form_values like *%~.@custom_search.~%*~, ARRAY_N);
     @l_ids=**; // whatever l_ids we have selected in the shortcode is now gone
     if(count(@my_custom_lists)>0){
      foreach (@my_custom_lists[0] as @v_post){@l_ids.=@v_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?

    #6048

    Hi,

    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

    – https://www.beprosoftware.com/documentation/architecture-built-to-scale/

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

    #6052
    Cosmin
    Member

    Thanks.
    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 ^_^

    #6053

    Completely understand 🙂

    ___
    BePro Software Team

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