• Hello,
    I created a page in wp admin to quickly publish videos, but i need to select a video category for that video and this is what i did so far but it doesnt work for me. I hope somebody can help me.

    $my_post['post_category'] = $video_category;
    
    <select name="video_category" class="widefat mid">
     <option value="video_category">Select Category...</option>
     <?php
      $categories=  get_categories('');
      foreach ($categories as $videocategory) {
      	$video_category = '<option value="/category/archives/'.$videocategory->category_nicename.'">';
    	$video_category .= $videocategory->cat_name;
    	$video_category .= selected($videocategory, $_POST['video_category']);
    	$video_category .= '</option>';
    	print ucfirst($video_category);
      }
     ?>
    </select>

Viewing 4 replies - 1 through 4 (of 4 total)
  • What is not working about it?

    Thread Starter JR Web Studio

    (@jetonr)

    Bump: anybody please…

    Thread Starter JR Web Studio

    (@jetonr)

    Well I can select a categoory for the post but I will show uncategorised allthough i can select the category from the drop down list. This is a custom page that I made for publishing, cant getthe categories to work.
    here is how i strucured it.

    // Category exists?
    if (!empty($_POST['video_category'])) {
    $video_category = $_POST['video_category'];
    } else {
    $video_category = 'Please select a category';
    }
    
    $my_post['post_category'] = array(prep($row['video_category'])); 
    
    <select name="video_category" class="widefat mid">
     <option value="video_category">Select Category...</option>
     <?php
      $categories=  get_categories('');
      foreach ($categories as $videocategory) {
      	$video_category = '<option value="/category/archives/'.$videocategory->category_nicename.'">';
    	$video_category .= $videocategory->cat_name;
    	$video_category .= selected($videocategory, $_POST['video_category']);
    	$video_category .= '</option>';
    	print ucfirst($video_category);
      }
     ?>
    </select>

    I still don’t quite understand what you’re doing… and parts of your code don’t make sense. Where is the $row array coming from, and what are you doing with $my_post? What does the selected() function do? (It looks like it’s trying to mark the selected option, but that won’t work because the <option> tag is closed in the line above it.) And why are you using the ucfirst() function? It won’t do anything because the first character of $video_category is non-alphabetic.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Select category for post in a custom publishing post page’ is closed to new replies.