wp query – Category and tag not pushing when send remote post

Question

I want to push post remotely to wp site, but all code is working but category and tags are not inserting on remote website, category_name and tag use slug so –

    $category_slugs = wp_get_post_terms($post_id, 'category', array('fields' => 'slugs'));
    $tag_slugs = wp_get_post_terms($post_id, 'post_tag', array('fields' => 'slugs'));

    // Ensure we have comma-separated strings for categories and tags
    $category_list = implode(',', $category_slugs);
    $tag_list = implode(',', $tag_slugs);

// Prepare the post data
    $post_data = array(
        'title' => $post_title,
        'status' => 'draft',
        'content' => $content,
        'category_name' => '$category_list',
        'tag' => $tag_list,
    );```

// And encapsulate it 
json_encode($post_data);

// send with 
wp_remote_post

0
Puneet 5 months 2023-10-20T05:02:52-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse