Pereiti prie turinio

Wordpress blog postai draft to published


Rekomenduojami pranešimai

Gal galit padėti sugalvoti kaip visus wordpress DRAFT blog postus reguliariai pakeisti į PUBLISHED?

Galbūt yra koks plugin arba tiesiog kokia kodo eilutė su cron job kuri tarkim kas 24 valandas visus DRAFT blog postus pakeistu į PUBLISHED automatiškai? 

Nuoroda į pranešimą
Dalintis kituose puslapiuose
Prieš 26 minutes, Gudruolis parašė:

Gal galit padėti sugalvoti kaip visus wordpress DRAFT blog postus reguliariai pakeisti į PUBLISHED?

Galbūt yra koks plugin arba tiesiog kokia kodo eilutė su cron job kuri tarkim kas 24 valandas visus DRAFT blog postus pakeistu į PUBLISHED automatiškai? 

image.png.df04a7744e4385f9c8a7a32b604c6149.png O šitoks variantas publishint "į ateitį" netinka?

Jei ne, AI siūlo tokį custom sprendimą:
 

// Schedule the event if it's not already scheduled
function wp_schedule_publish_drafts() {
    if ( ! wp_next_scheduled( 'publish_drafts_event' ) ) {
        wp_schedule_event( time(), 'daily', 'publish_drafts_event' );
    }
}
add_action( 'wp', 'wp_schedule_publish_drafts' );

// Hook the custom function to the event
function publish_all_draft_posts() {
    $args = array(
        'post_type'   => 'post',
        'post_status' => 'draft',
        'numberposts' => -1,
    );
    $draft_posts = get_posts( $args );

    foreach ( $draft_posts as $post ) {
        $post->post_status = 'publish';
        wp_update_post( $post );
    }
}
add_action( 'publish_drafts_event', 'publish_all_draft_posts' );

// Optional: Deactivate scheduled event on plugin/theme deactivation
function wp_clear_publish_drafts_event() {
    $timestamp = wp_next_scheduled( 'publish_drafts_event' );
    if ( $timestamp ) {
        wp_unschedule_event( $timestamp, 'publish_drafts_event' );
    }
}
register_deactivation_hook( __FILE__, 'wp_clear_publish_drafts_event' );


//// "Laikmatis"

 

function custom_cron_schedules( $schedules ) {
    $schedules['every_twenty_four_hours'] = array(
        'interval' => 86400, // 24 hours in seconds
        'display'  => __( 'Every 24 Hours' ),
    );
    return $schedules;
}
add_filter( 'cron_schedules', 'custom_cron_schedules' );

// Update the schedule event to use the custom interval
function wp_schedule_publish_drafts() {
    if ( ! wp_next_scheduled( 'publish_drafts_event' ) ) {
        wp_schedule_event( time(), 'every_twenty_four_hours', 'publish_drafts_event' );
    }
}
 

 

Redagavo Vileikis
Nuoroda į pranešimą
Dalintis kituose puslapiuose
prieš 2 valandas, Vileikis parašė:

image.png.df04a7744e4385f9c8a7a32b604c6149.png O šitoks variantas publishint "į ateitį" netinka?

Jei ne, AI siūlo tokį custom sprendimą:
 

// Schedule the event if it's not already scheduled
function wp_schedule_publish_drafts() {
    if ( ! wp_next_scheduled( 'publish_drafts_event' ) ) {
        wp_schedule_event( time(), 'daily', 'publish_drafts_event' );
    }
}
add_action( 'wp', 'wp_schedule_publish_drafts' );

// Hook the custom function to the event
function publish_all_draft_posts() {
    $args = array(
        'post_type'   => 'post',
        'post_status' => 'draft',
        'numberposts' => -1,
    );
    $draft_posts = get_posts( $args );

    foreach ( $draft_posts as $post ) {
        $post->post_status = 'publish';
        wp_update_post( $post );
    }
}
add_action( 'publish_drafts_event', 'publish_all_draft_posts' );

// Optional: Deactivate scheduled event on plugin/theme deactivation
function wp_clear_publish_drafts_event() {
    $timestamp = wp_next_scheduled( 'publish_drafts_event' );
    if ( $timestamp ) {
        wp_unschedule_event( $timestamp, 'publish_drafts_event' );
    }
}
register_deactivation_hook( __FILE__, 'wp_clear_publish_drafts_event' );


//// "Laikmatis"

 

function custom_cron_schedules( $schedules ) {
    $schedules['every_twenty_four_hours'] = array(
        'interval' => 86400, // 24 hours in seconds
        'display'  => __( 'Every 24 Hours' ),
    );
    return $schedules;
}
add_filter( 'cron_schedules', 'custom_cron_schedules' );

// Update the schedule event to use the custom interval
function wp_schedule_publish_drafts() {
    if ( ! wp_next_scheduled( 'publish_drafts_event' ) ) {
        wp_schedule_event( time(), 'every_twenty_four_hours', 'publish_drafts_event' );
    }
}
 

Taip rankiniu būdų netinka, reikia automatizacijos.

Šitas AI kodas irgi nelabai veikia. Gal atsirastu DEV kuris galėtų sukoduot funkcijos eilutę? Ne už ačiū žinoma.

Nuoroda į pranešimą
Dalintis kituose puslapiuose

Prisijunkite prie diskusijos

Jūs galite rašyti dabar, o registruotis vėliau. Jeigu turite paskyrą, prisijunkite dabar, kad rašytumėte iš savo paskyros.

Svečias
Parašykite atsakymą...

×   Įdėta kaip raiškusis tekstas.   Atkurti formatavimą

  Only 75 emoji are allowed.

×   Nuorodos turinys įdėtas automatiškai.   Rodyti kaip įprastą nuorodą

×   Jūsų anksčiau įrašytas turinys buvo atkurtas.   Išvalyti redaktorių

×   You cannot paste images directly. Upload or insert images from URL.

Įkraunama...
  • Dabar naršo   0 narių

    Nei vienas registruotas narys šiuo metu nežiūri šio puslapio.

×
×
  • Pasirinkite naujai kuriamo turinio tipą...