Hop you pepople would be fine. I'm creating a shortcode with the following code.

$categories = get_terms( 'project-type' );

foreach ($categories as $category) {

    $portfolio_terms[$category->slug] = $category->name;


$ABdevDND_shortcodes['portfolio_DD'] = array(
    'attributes' => array(
        'category' => array(
            'default' => 'all',
            'type' => 'select',
            'values' => $portfolio_terms,
            'description' => __('Category', 'dnd-shortcodes'),
        'style' => array(
            'default' => 'classic_gallery',
            'type' => 'select',
            'values' => array( 
                'classic_gallery' => 'Classic Style',
                'alternative_gallery' => 'Alternative Style',
            'description' => __('Style', 'dnd-shortcodes'),

    'description' => __('Portfolio', 'dnd-shortcodes' )
function ABdevDND_portfolio_DD_shortcode( $attributes, $content = null ) {
    extract(shortcode_atts(ABdevDND_extract_attributes('portfolio_DD'), $attributes));

    get_template_part( 'lib/blocks/portfolio', 'index' );  
    $return = ob_get_contents();  
    return $return;


shortcode is working just fine, but the only issue is i'm unable to populate taxonomy array values from $portfolio_terms variable. It outputs nothing.

The question is, how i populate category attribute with all avaiable terms of 'project-type' with slug as key and name as value?

  • Missing some code. For example, ABdevDND_extract_attributes? This looks like mostly a PHP problem right now though. – s_ha_dum Jan 17 '14 at 0:34
  • Solved the issue! This code is in plugin and taxonomy is being registered in theme files. Plugin files are loaded before theme files that why get_terms() returns nothing. – Faisal Khurshid Jan 17 '14 at 11:59
  • And that is why some things are best in plugins rather than themes. – s_ha_dum Jan 17 '14 at 14:29

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.