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.

Show "Similar" Postings

  1. schnettker
    Member

    Hi,

    i use gf to let the User populate Postings. I want to prevent them to Post "similar Content" (like the "Similar Topics" Box here). Can i use something similar to show the User (dynamicle) such Postings?

    joerg

    Posted 11 years ago on Saturday December 22, 2012 | Permalink
  2. David Peralty

    I'm sorry, I don't understand what you are looking for.

    Posted 11 years ago on Sunday December 23, 2012 | Permalink
  3. schnettker
    Member

    Sorry, my english isn't good. I try it again. If I start a topic in this forum, then tests the forum if there is a similar topic already. I want a similar function for my form. Use the form to send user entries for the website and I'd like to suppress duplicate entries.

    This is my form: http://www.gwinnr.de/ess-gewinnspiel-melden-2

    After the User is chosing "Anbieter" i would to show postings with the same "Anbieter" in the box below.

    Posted 11 years ago on Sunday December 23, 2012 | Permalink
  4. David Peralty

    Gravity Forms doesn't support showing entries in the front end of a site unless you make them WordPress posts through our Post Fields and then you could use a related posts plugin to pull in such details.

    If you wanted to do this without Post Fields, you'll have to custom code the PHP / SQL statements to do so. All my best!

    Posted 11 years ago on Sunday December 23, 2012 | Permalink
  5. schnettker
    Member

    Okay, i unterstand that there is no "out of the box" solution there. I try now to make my on solution and got one question: where can i modify a field with a "onChange" (Javascript) method?

    Posted 11 years ago on Tuesday December 25, 2012 | Permalink
  6. David Peralty

    Sure, you can watch remote fields using JS for an update, but you can't change the field code itself. All my best! Happy holidays!

    Posted 11 years ago on Tuesday December 25, 2012 | Permalink
  7. schnettker
    Member

    okay ... i spend the last four hours on the problem and solved it. The trick was admin-ajax, a html Element in the form, some jquery code and a custom query in the functions.php.

    You can close the topic

    Happy holidays!

    Posted 11 years ago on Tuesday December 25, 2012 | Permalink
  8. @schnettker, can you share your code here please for the benefit of others who may want to accomplish the same thing? Thank you.

    Posted 11 years ago on Wednesday December 26, 2012 | Permalink
  9. schnettker
    Member

    okay .... here comes some code. The code needs additionaly security checks! (proof the _POST Variable!)

    function.php (called by the javascript code)

    function AjaxSimilar(){
      //get the data from ajax() call
       $anbieter = $_POST['anbieter'];
       $query = new WP_Query( array( 'taxonomy'=>'anbieter', 'anbieter' =>  $anbieter) );
       while ( $query->have_posts() ) :
    	$query->the_post();
    	$results = $results .'<li>'.get_post_meta(get_the_ID(), 'einsendeschluss', true). ' - <strong>'.$anbieter.'</strong>  - ' . get_the_title() . '</li>'; 
    
       endwhile;
       if (!$query->have_posts())
       {
        $results = '<strong>No posts</strong>';
       }
        die($results);
      }
      // creating Ajax call for WordPress
       add_action( 'wp_ajax_nopriv_AjaxSimilar', 'AjaxSimilar' );
       add_action( 'wp_ajax_AjaxSimilar', 'AjaxSimilar' );

    Javascript (header.js.php in my template)

    $( document ).ready( function( $ ) {
       $('.anbieter').bind('change', function (){
          jQuery.ajax({
      type: 'POST',
      url: 'http://www.gwinnr.de/wp-admin/admin-ajax.php',
      data: {
      action: 'AjaxSimilar',
      anbieter: $('.anbieter div').find('span').text(),
      },
      success: function(data, textStatus, XMLHttpRequest){
       $('.similarbox').html('');
       $('.similarbox').append(data);
    
      },
      error: function(MLHttpRequest, textStatus, errorThrown){
      alert(errorThrown);
      }
      });
      });

    In my example i build a html form with the css class "similarbox" and a select with advanced controller with the css class "anbieter"

    The result is visible at http://www.gwinnr.de/ess-gewinnspiel-melden-2

    Posted 11 years ago on Wednesday December 26, 2012 | Permalink
  10. Neat solution: thank you for sharing your code.

    Posted 11 years ago on Wednesday December 26, 2012 | Permalink