Support » Fixing WordPress » Trying to retrieve category slug with PHP

  • Resolved amenitya


    I’ve searched through the forums and tried every combination suggested for retrieving the slug for my categories:

    $categories = $wpdb->get_col($cat_query);
    		foreach ($categories as $category) {
    			echo '<category>'.$category.'</category>'.
    			//add in slug

    …the category itself comes through fine, but the slug (I’ve checked a million times that its been assigned a slug of course) doesn’t appear:

    <?xml version="1.0" encoding="UTF-8"?>
    <channel><title>GeoMashup Query</title><item><category>alcachofa de Benicarló</category><slug></slug

    It’s probably a stupid syntax error, but I’d really appreciate it if someone could point it out to me.

Viewing 2 replies - 1 through 2 (of 2 total)
  • On a 2.6.3 test install, this listed all category slugs where the category had at least one post:

    $categories = get_categories();
    foreach($categories as $category){
    if($category->count > 0){
    echo $category->slug;

    Thanks so much.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Trying to retrieve category slug with PHP’ is closed to new replies.