Support

Account

Home Forums General Issues Custom field value in list of categories?

Helping

Custom field value in list of categories?

  • How do I echo a custom field value in a list of categories? Right now i’m using this;

    <?php $kategorier = array(
    	'show_option_all'    => '',
    	'orderby'            => 'name',
    	'order'              => 'ASC',
    	'style'              => 'list',
    	'show_count'         => 0,
    	'hide_empty'         => 0,
    	'use_desc_for_title' => 1,
    	'child_of'           => 0,
    	'feed'               => '',
    	'feed_type'          => '',
    	'feed_image'         => '',
    	'exclude'            => '1',
    	'exclude_tree'       => '',
    	'include'            => '',
    	'hierarchical'       => 1,
    	'title_li'           => '',
    	'show_option_none'   => __('No categories'),
    	'number'             => null,
    	'echo'               => 1,
    	'depth'              => 0,
    	'current_category'   => 0,
    	'pad_counts'         => 0,
    	'taxonomy'           => 'category',
    	'walker'             => null
    ); ?>
    
    <?php wp_list_categories ( $kategorier ); ?>

    And it’s being outputted as….

    <li class="cat-item cat-item-x"><a href="category-link">Category Title</a></li>

    Which is ruled by “category-template.php” in “wp-includes”.

    if ( 'list' == $args['style']){$output .= "\t						<li"; $class = 'cat-item cat-item-' . $category->term_id; if ( !empty($current_category) ) { $_current_category = get_term( $current_category, $category->taxonomy ); if ( $category->term_id == $current_category ) $class .=  ' current-cat'; elseif ( $category->term_id == $_current_category->parent ) $class .=  ' current-cat-parent';}$output .=  ' class="' . $class . '"';$output .= ">
    							$link\n";} else {$output .= "\t$link\n";}}function end_el( &$output, $page, $depth = 0, $args = array() ) {if ( 'list' != $args['style'] )return;$output .= "							</li>
    \n";}}
    

    Now, right after the opening li-element I have to echo the value of a field called “cf_produkter_kategorier_mini_thumb”. How would i go about doing that?

    • Elliot

    • October 30, 2013 at 4:46 pm

    Hi @cashless

    Modifying the core WP is not a smart move as it will be overridden by an update.

    You should read the docs about using a custom Walker class to output the data you want.

    As for actually getting ACF data for a taxonomy term, this is well documented. Please read the docs.

    Thanks
    E

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.