• Daddio

    (@thomasdickerson)


    I have the following shortcode created.

      function add_contestant_function() { 
    
          // Create post object
    
          $num = mt_rand ( 0, 0xffffff ); // created random number
          $idnum = sprintf ( "%06x" , $num ); // formats random number
          $newname = 'PC' . $idnum; // creates new contestant page from random number
          $newpass = 'MMV' . $idnum; // creates new contestant page from random number
          $my_post = array(
            'post_title'    => $newname,
            'post_status'   => 'publish',
            'post_author'   => $newname,
            'post_type'     => 'contestant'
          );
            
          // Insert the post into the database
          wp_insert_post( $my_post );
    
          ob_start();
          ?>
          <p><b>This is your page ID : <?php echo $newname; ?>
          <p>This is your page PASSWORD : <?php echo $newpass; ?></b>
          <?php
          return ob_get_clean();
    
      }
    
      add_shortcode('add_new_contestant', 'add_contestant_function');
    

    When it is added to a page it works as expected except that it creates two pages every time the page is accessed. I am not sure why. Please tell me what other information you may need to help me understand how to fix this.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi! I’ve tested your code with a fresh install, and I only got one page on each refresh… so maybe the page that contains your shortcode is getting loaded twice?

    • This reply was modified 4 years, 3 months ago by Javier Arce.
    Thread Starter Daddio

    (@thomasdickerson)

    We are using a purchased theme, should I contact that coder also.

    That’s a good idea; maybe they’ll know more about this.

    Another thing you could do is to check if you have any installed plugins that could be causing this reload and disable them momentarily.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Shortcode creating two pages’ is closed to new replies.