Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
deleted 9 characters in body
Source Link

I am currently using the ACF Relationship field selector to query through a custom post type for locations to show various pages. These pages are "service" pages that can be shown or hidden from the end user. The challenge is if the person de-selects the service page, it is technically still visible to the user if they know the link. I need to be able to set the page to a draft status or published when updating this option. Here is what I have based on other examples related to a similar request.

add_action('init','update_service_pages');
function update_service_pages () {
$the_query = get_postsmy_acf_update_value( 'post_type=services'$value, );$post_id, 
foreach($the_query$field as $service_post) {
    $services$ids = get_field('our_services', 'options');
    if(!$services){
   = get_posts(array(
        $update_post'post_type' ==> array('services',
            'post_status'   =>  'draft',
          'post__not_in' => 'post_type'$ids,
 =>  'services' ));
            wp_update_post($update_post$services);   
    }
     
}

}add_filter('acf/update_value/key=field_5c37e435', 'my_acf_update_value', 10, 4);

When I did this the first time it immediately set them all to draft from published without updating the ACF relationship field option. Do I need to hook into the "update" button in my options?

I am currently using the ACF Relationship field selector to query through a custom post type for locations to show various pages. These pages are "service" pages that can be shown or hidden from the end user. The challenge is if the person de-selects the service page, it is technically still visible to the user if they know the link. I need to be able to set the page to a draft status or published when updating this option. Here is what I have based on other examples related to a similar request.

add_action('init','update_service_pages');
function update_service_pages () {
$the_query = get_posts( 'post_type=services' ); 
foreach($the_query as $service_post) {
    $services = get_field('our_services', 'options');
    if(!$services){
            $update_post = array(
            'post_status'   =>  'draft',
            'post_type' =>  'services' );
            wp_update_post($update_post);   
    }
    }

}

When I did this the first time it immediately set them all to draft from published without updating the ACF relationship field option. Do I need to hook into the "update" button in my options?

I am currently using the ACF Relationship field selector to query through a custom post type for locations to show various pages. These pages are "service" pages that can be shown or hidden from the end user. The challenge is if the person de-selects the service page, it is technically still visible to the user if they know the link. I need to be able to set the page to a draft status or published when updating this option. Here is what I have based on other examples related to a similar request.

function my_acf_update_value( $value, $post_id, $field  ) {
    $ids = get_field('our_services', 'options');
    $services = get_posts(array(
        'post_type' => 'services',
        'post_status' => 'draft',
        'post__not_in' => $ids,
    ));
    wp_update_post($services);
         
}

add_filter('acf/update_value/key=field_5c37e435', 'my_acf_update_value', 10, 4);

When I did this the first time it immediately set them all to draft from published without updating the ACF relationship field option. Do I need to hook into the "update" button in my options?

Source Link

Using ACF Relationship field to set post type to draft or published status

I am currently using the ACF Relationship field selector to query through a custom post type for locations to show various pages. These pages are "service" pages that can be shown or hidden from the end user. The challenge is if the person de-selects the service page, it is technically still visible to the user if they know the link. I need to be able to set the page to a draft status or published when updating this option. Here is what I have based on other examples related to a similar request.

add_action('init','update_service_pages');
function update_service_pages () {
$the_query = get_posts( 'post_type=services' ); 
foreach($the_query as $service_post) {
    $services = get_field('our_services', 'options');
    if(!$services){
            $update_post = array(
            'post_status'   =>  'draft',
            'post_type' =>  'services' );
            wp_update_post($update_post);   
    }
    }

}

When I did this the first time it immediately set them all to draft from published without updating the ACF relationship field option. Do I need to hook into the "update" button in my options?