WordPress.org

Forums

get slug from given id (2 posts)

  1. hafman
    Member
    Posted 2 years ago #

    I'm trying to pass a taxonomy slug to a loop. I have a custom field that sends an ID of 6. I want to 'get the slug' for this and feed it to the query (they like slugs)

    $slid = get_field('slideset_slug');//advanced custom fields plugin
    	$term = get_term($slid, 'slide-set');
    	$slug = $term->slug;
    
    $slideLoop = new WP_Query( array(
    	'post_type' => 'slide',
    	'posts_per_page' => 10,
    	'slide-set' => $slug
  2. hafman
    Member
    Posted 2 years ago #

    ok, not sure if it's slugs on toast or 'spaghetti con slugs' but it works now after consulting the ACF code examples

    $values = get_field('slideset_slug');//should be called slideset_id!
    	if($values) {
    	foreach($values as $slid)//blah blah blah give me the key
    	{
    	$term = get_term($slid, 'slide-set');
    	$slug = $term->slug;
    	}
    }
    	$slideLoop = new WP_Query( array(
    	'post_type' => 'slide',
    	'posts_per_page' => 10,
    	'slide-set' => $slug //ca chunk
    	));

Topic Closed

This topic has been closed to new replies.

About this Topic