• Resolved testerteej

    (@testerteej)


    Hi,

    I’ve been trying to interface with the Rest API, my scenario is that I am creating a new redirection item for a new post when its created, the target url will be the permalink of this new post.

    My issue is when I trash the post, I expect it to change the status of the redirection to ‘disabled’, but it does not seem to work, only the target url get’s updated, here’s a screenshot:

    View post on imgur.com

    The parameters I pass is this:

    View post on imgur.com

    I am using the action:
    add_action( 'transition_post_status', 'createRedirect', 10, 3 );

    And in the function:

    
    ...
    // When trashed
          elseif ( ( $new == 'trash' ) && ( $old == 'publish' ) ) :
    
            //wp_die(var_dump($new) . var_dump($old));
            
            $redirectSlugID = get_field('redirect_id', $post->ID);
    
            $params['url'] = get_field('short_url_slug', $post->ID);
            $params['status'] = "disabled";
    
            //wp_die(var_dump($params));
    
            $request = new WP_REST_Request( 'POST', '/redirection/v1/redirect/' .  $redirectSlugID);
            $request->set_query_params( $params );
            $response = rest_do_request( $request );
    
          else :
            return;
          endif;
    ...
    
    • This topic was modified 3 years, 9 months ago by testerteej.
    • This topic was modified 3 years, 9 months ago by testerteej.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter testerteej

    (@testerteej)

    Hi John,

    is the Rest API guide somehow not up to date?

    I noticed that the request response data, in particular the “status” field has been changed to “enabled=true”.

    View post on imgur.com

    I am wondering how to correctly update the status of redirection item via rest API.

    • This reply was modified 3 years, 9 months ago by testerteej.
    Plugin Author John Godley

    (@johnny5)

    The API doesn’t currently support a status change in that way. If you look at what happens when you enable/disable a redirect from the UI you will see the only currently supported way.

    Thread Starter testerteej

    (@testerteej)

    Hi John,

    I have found that it works by doing it this way:

    
    $request = new WP_REST_Request( 'POST', '/redirection/v1/bulk/redirect/delete');
    $request->set_param( 'items', $shortUrlID);
    $response = rest_do_request( $request );
    

    Thanks a lot!

    Regards,
    Teej

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Rest API redirection update status disabled not working’ is closed to new replies.