Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 504799

Front End widget updating Post Type

$
0
0

Replies: 0

I’m working on a widget, which can post data from front-end of wordpress to a Post Type in the backend.

I’ve created a small test to see if it works, but somehow, whenever I post something to the Post Types, the same post appears 5 times. My code for the widget is:

class Add_teams_widget extends WP_Widget {

/**
 * Sets up the widgets name etc
 */
 public function __construct() {
   $widget_options = array( 'classname' => 'Add_teams', 'description' => 'Tilføj hold til klub' );
   parent::__construct( 'Add_teams', 'Tilføj hold', $widget_options );
 }

/**
 * Outputs the content of the widget
 *
 * @param array $args
 * @param array $instance
 */
public function widget( $args, $instance ) {
    // outputs the content of the widget

  $i = get_field('field_589d785231349', 204);
  $i_inc = $i + 1;
  update_field( 'field_589d785231349', $i_inc, 204 );

  echo 'hello ' . $i . 'World';
}

/**
 * Ouputs the options form on admin
 *
 * @param array $instance The widget options
 */
public function form( $instance ) {
    // outputs the options form on admin
}

/**
 * Processing widget options on save
 *
 * @param array $new_instance The new options
 * @param array $old_instance The previous options
 */
  public function update( $new_instance, $old_instance ) {
    // processes widget options to be saved
 }

}

   // Register the widget with WordPress. Requires PHP5.3+.
   add_action( 'widgets_init', function(){
      register_widget( 'Add_teams_widget' );
    });

When I reload the page, $i increases by 5 every time (e.g.: 5 -> 10 -> 15), it’s like the code/page is being reloaded 5 times.

What is going on? 🙂


Viewing all articles
Browse latest Browse all 504799

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>