The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

[resolved] Trying to retrieve category slug with PHP (3 posts)

  1. amenitya
    Posted 7 years ago #

    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.

  2. MichaelH
    Posted 7 years ago #

    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;
  3. amenitya
    Posted 7 years ago #

    Thanks so much.

Topic Closed

This topic has been closed to new replies.

About this Topic