• Resolved maximgrachev

    (@maximgrachev)


    Hi, I’m looking for a plugin that will solve my problem. I want to have a list of checkboxes that take values from custom fields from a post (there is a function called “genesis_get_custom_field(field_id)” that I can use), and finally calculate the total of the ones that are checked.

    I haven’t found ANY plugin yet that can do this ?? checkboxes always have to have a static value, but I need it to vary from post to post (each post is actually a house/property, with its own base-price, roof-price, etc.) And I don’t want to create a form for each model (~60 houses, too many forms).

    Is it possible with Calculated Fields? I don’t mind changing code, I just need some kind of tip to get started. Thanks!!!

    https://www.ads-software.com/plugins/calculated-fields-form/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author codepeople

    (@codepeople)

    Hi,

    In your description there are some points that are not very clear, but if you know the database structure, you can use the Developers version of the plugin that includes a group of fields (identified with the “DS” text in their names), that are populated from external data-sources, like databases, and then, to use these fields in the equations, like any other field in the form. So, with only one form, you can evaluate the prices of all houses/properties.

    Best regards.

    Thread Starter maximgrachev

    (@maximgrachev)

    Hi,

    Thanks. I have no problem in purchasing the Developer version. I just don’t want to purchase something that in the end may not suffice (and I guess there is no money back guarantee ?? ).

    What I wanted, is just to associate somehow the value of the price of a house. This price is in a custom field (for example: ‘_listing_price’). And I’ve seen there is a wordpress function to access these custom fields’ values:

    <?php get_post_custom_keys($post_id); ?>

    What I wanted to know is if there is a way to use that for the checkboxes. Even if it actually means assigning the value to a hidden field, and using that field for the checkbox. I just want the value. I don’t know if there are any tutorials maybe about this. Usually I have everything in my head, but can’t explain it easily enough :S

    Maybe as an example (currently using NinjaForms, but not working): https://www.supercastor.net/wordpress/listings/castellon-65-m2-ytong/

    Price would the custom field “Precio básico”, which evaluates to 19000

    Thanks!!

    Thread Starter maximgrachev

    (@maximgrachev)

    Sorry, my bad, the function is actually:

    <?php get_post_custom_values($key, $post_id); ?>

    Plugin Author codepeople

    (@codepeople)

    Hi,

    With our plugin you cannot get the values directly with the function:

    get_post_custom_values($key, $post_id);

    The custom fields are usually stored in the database’s table: wp_postmeta

    and you can populate a “Checkbox DS” field with a query similar to:

    SELECT meta_value as value, meta_value as text FROM wp_postmeta WHERE post_id=### AND meta_key='key_name'

    If you create a javascript variable with the id of the current post, for example: the mypost variable, the query to use would be:

    SELECT meta_value as value, meta_value as text FROM wp_postmeta WHERE post_id=<%mypost%> AND meta_key='key_name'

    Best regards.

    Thread Starter maximgrachev

    (@maximgrachev)

    Wow! That may even work ?? I’ve tried using the DEMO with a connection to my database, and I am almost there…

    But do I have to use javascript? Can’t I pre-populate a hidden field or something like that with the POST_ID? I’ve seen something like that in the demo, but haven’t been able to use it.

    And then it would only be a matter of:

    SELECT meta_value as value, meta_value as text FROM wp_postmeta WHERE post_id=<%fieldnameX%> AND meta_key='key_name'

    Right? Where fieldnameX is the hidden field, although as I said, I am not able to fill it this way. I get NULL value.

    Thanks!!!

    Plugin Author codepeople

    (@codepeople)

    Hi,

    First, be sure you can connecting with your database server from the IP of my demo website (sometimes the database servers limit the access by IP), and second, uses the real name of the ‘meta_key’ in the query. Remember, I’m assuming your website stores the custom values in the wp_postmeta table.

    Best regards.

    Thread Starter maximgrachev

    (@maximgrachev)

    Yes, yes, everything works (connection, and query), but I guess that since the Post_id is not actually there (maybe the demo form is on a “page”, not a post, or something like that), it probably does not evaluate as I need it to.

    I’ll keep trying, but it seems that the Developer would be the option for me. I guess that the other versions do not support Database accesses.

    Thanks a lot! You’re probably the one that will solve this ?? I’ve been looking for a solution for months now, haven’t been able to start the website going, because I needed this “feature”.

    Plugin Author codepeople

    (@codepeople)

    Hi,

    You can generate a javascript variable from the template file of your theme used in pages for properties or houses, and then, to use the variable in the query as I’ve explained previously.

    The plugin includes other shortcodes, one of them allows generate the javascript variables, from parameters received by GET or POST, or from SESSION VARIABLES. So, if you pass the post id as a parameter to the page, you can use this shortcode to generate the javascript variable without modify the template file.

    Best regards.

    Thread Starter maximgrachev

    (@maximgrachev)

    Hi again,
    I thought the post_id is something like an “global variable”. And can be easily accessible via a php function: get_the_id();

    Anyways, I’ve tried the demo. I’ve created 3 posts, and put new CP_CALCULATED_FIELDS form, with a TEXT AREA DS field, which should provide the Post Id, at least that’s how I specified the options:
    Define datasource –> Post type
    Select Post Type –> Post type –> post
    Attribute for values –> ID

    But it ALWAYS (in all 3 posts) evaluates to the first post created. I understood that this should fill the TEXT field with the ID of each post, but it only does so for the first post, not the other 2…

    Am I missing something?

    Thanks again!!

    Plugin Author codepeople

    (@codepeople)

    Hi,

    Ok, suppose you want to populate the “TEXT AREA DS” field with the content of a specific post:

    1. Inserts the “TEXT AREA DS” field in the form.

    2. Select “Post Type” as datasource.

    3. If you want to load the content of a post, select “post”, in the “Post Type” attribute, or page, if you want to get the content of a page.

    4. Selects the option “post_content” for the attribute: “Attribute for values”

    5. Finally, you should enter the ID of the post you want to load.

    I guess you’ve omitted the fifth step, in the process, in whose case would be returned the content of the first post.

    Best regards.

    Thread Starter maximgrachev

    (@maximgrachev)

    Hi,
    Yes, exactly. I thought that omitting the step 5 would actually evaluate to the “current” post where the Form was inserted into. But it seems that this has to be hardcoded. Or as you say, use somehow a javascript function to create a variable with the post id.

    Thanks. I’ll keep trying. Because my most difficult concern is that of being able to “filter” the postmeta for the specific post where the form is in.

    Thanks!!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Custom field value as checkbox "checked"?’ is closed to new replies.