1

I am using this code to select category,now i want to save the selected category in variable and pass it to wp rest api post url..

  echo '<select name="categories">';
  // Add custom option as default
  echo '<option>' . __('No Category', 'text-domain') . '</option>';

  // Get categories as array
  $categories = get_categories( $args );
  foreach ( $categories as $category ) :

      // Check if current term ID is equal to term ID stored in database
      $selected = ( $stored_category_id ==  $category->term_id  ) ? 'selected' : '';

      echo '<option value="' . $category->term_id . '" ' . $selected . '>' . $category->name . '</option>';

  endforeach;

echo '</select>';
  • sir, i am creating post from frontend and want to assign category to that post – M Saadat Mar 3 '17 at 12:22
  • Yes but what have you tried with the saving process and where is the problem? – Laxmana Mar 3 '17 at 12:29
  • createPost.open("POST", magicalData.siteURL + "/wp-json/wp/v2/posts?filter[category_name]=latest/"); I want to add selected value in category name in rest api post – M Saadat Mar 3 '17 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.