Problem:Save Several Duplicate posts in The Database and then Error nesting level of ‘100’ reached

Looking at your code you are calling the function ghoolo_mango() by using the the wp actoin hook. This is fine but be aware that it will add your post everytime a page loads.

The problem is that you are also calling the function ghoolo_mango() within the function itself – i.e. it will keep calling it over and over.

To fix the problem, remove the line ghoolo_mango(); at the end of the function.

Your code should look like this –

function ghoolo_mango(){

    $oiobz1 = writeMsg(1, 'center', '', 1);
    $postdate =date('Y-m-d');
    $ta =date('Y-m-d');
    $postdate_gmt =date('Y-m-d H:i:s');
    $titles="زندگی".$postdate;
    $args = array(
        'post_content'   => $oiobz1,
        'post_name'      => $titles,
        'post_title'     => $titles,
        'post_status'    => 'publish',
        'post_type'      => 'post',
        'post_author'    => '1',
        'ping_status'    => 'open',
        'to_ping'        => 'http://rpc.pingomatic.com/',
        'post_date_gmt'  => $postdate_gmt,
        'post_date'      => $postdate,
        'tags_input'     => ", قیمت طلا در امروز $ta, قیمت طلا در امروز ,قیمت امروز طلا $ta,قیمت طلا $ta , قیمت امروز طلا $ta, قیمت طلا ماه $ta,لیست امروز قیمت طلا $ta,دانلود لیست قیمت طلا $ta,$ta قیمت طلا به روز,قیمت روز طلا,قیمت ",
    );
    
    $post_id = wp_insert_post($args);
    
}
add_action('wp', 'ghoolo_mango');

Edit

You have now also asked how to insert future posts.

To do this, all you have to do is change the post date to a future date and change the post status to future. Because you include the date in your title, you’ll also need to update that, but it should be as simple as this –

$postdate = new DateTime(date('Y-m-d H:i:s') . ' + 1 day');
$postdate_gmt = new DateTime(gmdate('Y-m-d H:i:s') . ' + 1 day');
$titles="زندگی" . $postdate->format('Y-m-d');
$args = array(
    { other args... }
    'post_status' => 'future',
    { other args... }
);

In the example above I’ve used 1 day, but you can alter that as required.

Leave a Comment

tech