PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Query advice

  1. rbl
    Member

    Hi!
    I have a simple form with 2 fields: a multiple answer with Yes and No values and a hidden IP address.
    This form was made with generic labels to be duplicated every time it's needed in a new post.

    In every post where a form was included, I need to pull the results and display them and for this purpose, I think it would be better to manipulate the query and results directly in the template, lets say in the single post php file.

    I would appreciate your help in the following as I've found no answer in the docs and forum:
    - the best way to determine if the current post has a form (so that it executes or ignores the code bellow);
    - if it has a form, getting its ID and;
    - querying the database in a sensible way to take full advantage of a caching plugin like W3 Total Cache;

    Thanks for your help!
    Ricardo

    Posted 9 years ago on Friday May 27, 2011 | Permalink
  2. Hi Ricardo,

    Would the output of your custom code be displayed before or after the form?

    Posted 9 years ago on Saturday May 28, 2011 | Permalink
  3. rbl
    Member

    Hi David!

    After!

    Ricardo

    Posted 9 years ago on Saturday May 28, 2011 | Permalink
  4. Hi Ricardo,

    You'll want to paste this function in your theme's functions.php file: http://pastie.org/1984439

    And you'll want to paste this snippet in your page template file wherever you are intending to output your custom code: http://pastie.org/1984444

    You can ditch the "print_rr" stuff, but it's useful for debugging by making larger arrays very readable.

    In regards to the best way to make queries, just use the $wpdb class. More information here:

    http://codex.wordpress.org/Class_Reference/wpdb

    Posted 9 years ago on Saturday May 28, 2011 | Permalink
  5. rbl
    Member

    Thanks David but something is not working. Whatever code I place in functions seems to work, but I'm getting nothing from the template file, I can't even get it to echo the form id!

    I've been trying snippets and everything i've found here for most of the last hours.
    Would appreciate if you can help me out as I feel I hit a wall.

    Thanks!
    Ricardo

    Posted 9 years ago on Saturday May 28, 2011 | Permalink
  6. Hi Ricardo,

    Are you sure you are loading the correct page template? Try putting an <?php echo 'Test!'; ?> at the very top of whatever page template and see if it outputs 'Test!' to the screen.

    Posted 9 years ago on Monday May 30, 2011 | Permalink
  7. rbl
    Member

    Hi David!
    I'm quite sure it's the right template as other elements I'm editing display.

    I've tried all variants of "$form = RGFormsModel::get_form_meta($form_id);" I've found in the forum threads and none, absolutely none, displays the form id, which I need to use in my query.

    Ricardo

    Posted 9 years ago on Wednesday June 1, 2011 | Permalink
  8. Hi Ricardo,

    If you send me a login to your WP admin and FTP, I will take a look.

    Posted 9 years ago on Wednesday June 1, 2011 | Permalink
  9. rbl
    Member

    Thanks David! Where shall I send them to?

    Ricardo

    Posted 9 years ago on Wednesday June 1, 2011 | Permalink
  10. Sorry, Rbl, email is david@rocketgenius.com.

    Posted 9 years ago on Thursday June 2, 2011 | Permalink