Forum Replies Created

Viewing 15 replies - 1 through 15 (of 31 total)
  • Thread Starter dmunaretto

    (@dmunaretto)

    Just an update, I have the form working such that it filters the result set based on the city chosen from the list of all cities, but still haven’t been able to figure out how to get just those cities that are within the result set into the form <option>s…

    Here’s the code that works, I know someone else was interested…

    [pass global=query field=filter]
    [for each=property-city current=false]
    [set filtval][each id][/set]
    [-if var=filtval value='{FILTER}’]
    [set citylabel][each name][/set] (NOTE: I’M USING THIS ELSEWHERE IN CODE TO HEADING THE NAME OF SELECTED CITY.)
    [/-if]
    [/for]

    [form action=]
    [b]<i class=”fa fa-street-view” aria-hidden=”true”></i>Show Matching Properties In:[/b]
    [select name=filter]
    <option value=””>Select a City</option>
    [for each=property-city field=name order=ASC]

    <option value=[each id][-if each_field=id each_value='{FILTER}’] selected[/-if]>[each]</option>

    [/for]
    [/select]

    [input type=submit]
    [/form]
    [/pass]

    Thread Starter dmunaretto

    (@dmunaretto)

    My [-if] is nested only because it is running inside of another if statement in my code, but obviously not needed to be that way otherwise.

    – I have the form before the loop with a select called [filter] and each option value as [each id] from the taxonomy.
    – Then in the loop I’m passing [filter] to an [if] so that it only shows results that match the [filter].

    This works, but what I really want to do is:
    1) Within the loop create a variable [validcities] for each property-city within the search results.
    2) Pass that variable into the form select [filter] as each <option> in the form.
    3) In the loop if a user sets a [filter] from the form, limit the results of the search to the selected [filter].

    I see how your code works, but not sure how I would pass back into the form…? I think your code would need to be something like this —

    [for each=whatever current=true order=ASC]
    [set test][each count][/set]
    [if var=test value=’0′ compare=more]
    [set validcity][each id][/set]
    [/if]
    [/for]

    Then how do i pass back into the [form] —- something like this?

    [pass global=_GET field=validcity]
    [form action=]
    <i class=”fa fa-street-view” aria-hidden=”true”></i> I’m looking for a home in:
    [select name=filter]
    [for each=property-city field=name order=ASC]
    [set taxidlist][each id]
    [if var=validcity compare=”exists”]
    [-if var=taxidlist compare=”=” value='{VALIDCITY}’]
    <option value=[each id]>[each]</option>
    [/-if]
    [else]
    <option value=[each id]>[each]</option>
    [/for]
    [/select]

    [input type=submit]
    [/form]
    [/pass]

    • This reply was modified 3 years, 4 months ago by dmunaretto.
    Thread Starter dmunaretto

    (@dmunaretto)

    What I’m trying to do is something that I can pass back to the form input so that only the taxonomy terms that have results within the loop show up in the <select> options.

    Was thinking something like this but can’t seem to make it work –
    [for each=property-city order=ASC current=true]
    [set validitem][each count][/set]
    [-if var=validitem compare=”>” value=0]
    [set taxtitle][field name][/set]
    [/-if]

    Thread Starter dmunaretto

    (@dmunaretto)

    This works although it doesn’t limit the results to those taxonomy terms that are in the search results… I’m also having performance issues with it, but may just need to reorganize some things in my code —

    BEFORE THE LOOP:
    [form action=]
    <i class=”fa fa-street-view” aria-hidden=”true”></i> I’m looking for a home in:
    [select name=filter]
    [for each=property-city field=name order=ASC]

    <option value=[each id]>[each]</option>

    [/for]
    [/select]

    [input type=submit]
    [/form]

    THIS IN THE LOOP BEFORE YOUR PRESENTATION / HTML STUFF –

    [-pass global=_GET field=filter]
    [set taxfilter][taxonomy property-city field=id][/set]
    [–if var=taxfilter value='{-FIELD}’]
    [/note]

    Hope it helps —

    David

    Thread Starter dmunaretto

    (@dmunaretto)

    Let me add that I would REALLY LIKE to be able to only show those taxonomy terms that had search results by using the [COUNT] feature, that would be the ultimate goal. I had an idea to do something like this — but since I’m building the form before the loop, not sure how to do it — maybe setup all items as variables then close the loop and generate the content display?

    [for each=property-city order=ASC current=true]
    [set validitem][each count][/set]
    [-if var=validitem compare=”>” value=0]
    [set taxtitle][field name][/set]
    [/-if]

    Then use this in the [form]…

    Thread Starter dmunaretto

    (@dmunaretto)

    Got it figured out — was a simple oops – [pass vars] not pass field–

    Thank you for your help! I didn’t actually realize that I needed the {- on the -pass so it was a huge assist – thanks again!

    David

    [-pass vars]
    [for each=property-city term='{-LAKE}’ current=false]
    ….
    [/-pass]

    you can also use
    [pass vars]
    [if var=dif compare=”>” value=’0′]
    Increase
    [else]
    Decrease
    [/pass]

    Thread Starter dmunaretto

    (@dmunaretto)

    Still no — I also added empty=true even though i made sure there was a post associated with it….

    [–if var=uninc value=YES]
    [set countyname]Unincorporated [field real_estate_county] County[/set]

    [-pass field=countyname]
    [for each=property-city term=”{FIELD}” current=false empty=true]
    [set lake][field id][/set]
    [/for]
    [/-pass]

    [–else]
    [set countyname][taxonomy property-city field=name][/set]
    [set lake][taxonomy property-city field=id][/set]

    [/–if]

    Thread Starter dmunaretto

    (@dmunaretto)

    Thats returning the value of the current post… 🙁 Appreciate the suggestion though 😉

    What I need to do is:

    Loop through ALL taxonomy property-city posts (not just those associated with the post)
    Get the one post that matches name {COUNTYNAME}
    And then set the variables to be used from that post

    Any ideas?

    I use it all the time. Works without flaw for me.

    Thread Starter dmunaretto

    (@dmunaretto)

    Thanks everyone. Marked as resolved.

    Thread Starter dmunaretto

    (@dmunaretto)

    THIS IS HOW I WAS ABLE TO CREATE A DOWNLOAD FROM FRONT END USING GRAVITY FORMS:

    Pratik – thank you for your help, this can be marked as closed, and I’m posting here for anyone who needs in future.

    Put this in your functions.php file or install snippets plugin…

    add_action(“gform_after_submission_27”, “create_download_from_submission”, 10, 2);
    function create_download_from_submission($entry, $form)
    {

    //Create the Array for the Variable Product Prices

    $dlarray = array(

    ‘1’ => array(
    ‘index’ => 1,
    ‘name’ => “PDF”,
    ‘amount’ =>($entry[15])
    ),

    ‘2’ => Array(
    ‘index’ => 2,
    ‘name’ => “CAD”,
    ‘amount’ =>($entry[17])
    )

    );
    //Create the array for the download files to associate to the variable price items in dlarray.
    $downloadfiles = array(
    ‘1’ => array(
    ‘index’ => “1”,
    ‘attachment_id’ => “0”,
    ‘thumbnail_size’ => “”,
    ‘name’ =>””,
    ‘file’ => ($entry[20]),
    ‘condition’ =>”1″,
    ),

    ‘2’ => array(
    ‘index’ => 2,
    ‘attachment_id’ => “0”,
    ‘thumbnail_size’ => “”,
    ‘name’ =>””,
    ‘file’ =>($entry[21]),
    ‘condition’ =>”2″,

    ));

    // create the post in its basic form
    $new_download = array(
    ‘post_title’ => ucwords($entry[5]),
    ‘post_status’ => ‘publish’,
    ‘post_date’ => date(‘Y-m-d H:i:s’),
    ‘post_type’ => ‘download’,
    //USE META_INPUT TO SET META DATA. UPDATE_POST_META did not want to play nice with our variable price array. This worked like a charm.
    ‘meta_input’ => array(
    ‘_variable_pricing’ => ($entry[9]),
    ‘plan_property_id’ => ($entry[14]),
    ‘edd_variable_prices’ => $dlarray,
    ‘edd_download_files’ => $downloadfiles
    )
    );

    //From creating it, we now have its ID
    $theId = wp_insert_post($new_download);

    //update_post_meta($post_id, ‘edd_variable_prices’, $array);
    update_post_meta($theId, edd_price, ($entry[15]));
    //entry 15 is the lowest price -item 1 in my price options. you can make this more complicated.
    update_post_meta($theId, _edd_default_price_id, 1);
    //this sets default price item to whatever item ID you want to be default.

    }

    Thread Starter dmunaretto

    (@dmunaretto)

    OK my code creates the array (actually both $array and $dlarray create the correct array), and when serialized it appears to be correct. It sets variable price to 1 and it shows up as selected when you open the download from the admin screen, but it doesn’t save data to edd_variable_prices. Any suggestions>?

    add_action(“gform_after_submission_27”, “create_download_from_submission”, 10, 2);
    function create_download_from_submission($entry, $form)
    {

    //First need to create the post in its basic form
    $new_download = array(
    ‘post_title’ => ucwords($entry[5]),
    ‘post_status’ => ‘publish’,
    ‘post_date’ => date(‘Y-m-d H:i:s’),
    ‘post_type’ => ‘download’
    );
    //From creating it, we now have its ID
    $theId = wp_insert_post($new_download);
    //Now we add the meta

    update_post_meta($theId, _variable_pricing, ($entry[9]));
    //This sets variable pricing to on and works.
    update_post_meta($theId, plan_property_id, ($entry[14]));
    //This associates the download product to the “Floor Plan” product within the real estate listing system

    //Create the Array for the Variable Product Prices

    $dlarray = array(

    ‘1’ => array(
    ‘index’ => 1,
    ‘name’ => “PDF”,
    ‘amount’ =>($entry[15])
    ),

    ‘2’ => Array(
    ‘index’ => 2,
    ‘name’ => “CAD”,
    ‘amount’ =>($entry[17])
    )

    );

    $array;
    $array[“1”];
    $array[“1”][“index”] = “1”;
    $array[“1”][“name”] = “PDF”;
    $array[“1”][“amount”] = ($entry[15]);

    $array[“2”];
    $array[“2”][“index”] = “2”;
    $array[“2”][“name”] = “CAD”;
    $array[“2”][“amount”] = ($entry[17]);

    $str = serialize($array);

    $message= print_r($str);

    update_post_meta($post_id, ‘edd_variable_prices’, $array);
    update_post_meta($theId, edd_price, ($entry[15]));
    update_post_meta($theId, _edd_default_price_id, 1);

    }

    FROM $MESSAGE ON CONFIRMATION SCREEN:

    a:2:{i:1;a:3:{s:5:”index”;s:1:”1″;s:4:”name”;s:3:”PDF”;s:6:”amount”;s:2:”36″;}i:2;a:3:{s:5:”index”;s:1:”2″;s:4:”name”;s:3:”CAD”;s:6:”amount”;s:2:”46″;}} (this is $str)

    Array ( [1] => Array ( [index] => 1 [name] => PDF [amount] => 36 ) [2] => Array ( [index] => 2 [name] => CAD [amount] => 46 ) ) (this is $array)

    Thread Starter dmunaretto

    (@dmunaretto)

    OK so I think you are saying that because I have $array = $_POST[‘variableprice’] it is overwriting $array argument used earlier. So… if I comment out $_POST I would have expected it to write the array using update_post_meta — but that didn’t work. (I also changed $array to $downloadarray, and set edd_price to 1 and edd_default_price_id to 1 afterwards. Here’s updated code…. Should edd_price point to an index or an amount?

    add_action(“gform_after_submission_27”, “create_download_from_submission”, 10, 2);
    function create_download_from_submission($entry, $form)
    {
    //First need to create the post in its basic form

    $new_download = array(
    ‘post_title’ => ucwords($entry[5]),
    ‘post_status’ => ‘publish’,
    ‘post_type’ => ‘download’
    );

    //From creating it, we now have its ID
    $theId = wp_insert_post($new_download);
    //Now we add the meta
    update_post_meta($theId, _variable_pricing, ($entry[9]));
    update_post_meta($theId, plan_property_id, ($entry[14]));
    //Create the Array for the Variable Product Prices
    $downloadarray = array(
    ‘variableprice’ => array(
    ‘1’ => array(
    ‘index’ => 1,
    ‘name’ => “PDF”,
    ‘amount’ =>($entry[15])
    ),
    ‘2’ => Array(
    ‘index’ => 2,
    ‘name’ => “CAD”,
    ‘amount’ =>($entry[17])
    )
    )
    );
    //$array = $Post[‘variableprice’];
    update_post_meta( $theID,_edd_variable_prices, $downloadarray );
    update_post_meta($theId, edd_price, 1);
    update_post_meta($theId, _edd_default_price_id, 1)
    ;
    }

    I do it all the time. Just wrap the [gravityform id=##] inside of a custom content shortcode and you take the whole thing into your own hands.

Viewing 15 replies - 1 through 15 (of 31 total)