New Landing How can we help? Themeforest Theme Support Dante Show custom field on portfolio category page

Viewing 8 posts - 1 through 8 (of 8 total)
  • Posted in: Dante
  • #317053
    morruu
    Member
    Post count: 106

    Hi

    I have managed to create an extra field on the portfolio category page with help from the ACF plugin.

    It’s visible in backend, so I can enter an extra long description for the portfolio categories.

    My problem is the content from the field will not show up in frontend.

    I have set location rule to taxonomy term equal to portfolio category and named the field “portfolio_long_category_description”.

    I tried the following code in the template taxonomy-portfolio-category.php:

    <?php $category_id = get_queried_object_id(); ?>
    <?php $cat_id = 'category_'.$category_id; ?>
    <?php $portfolio_long_category_description = get_field( 'portfolio_long_category_description', $cat_id); ?>
    <?php echo get_field('portfolio_long_category_description'); ?>

    I know it’s a question regarding customization, but maybe you could point me in the right direction?

    Best regards
    Morten

    #317059
    David Martin – Support
    Moderator
    Post count: 20834

    You would need to consult with the ACF plugin docs, these will tell you how to extra meta data such as you are trying to do.

    Thanks.

    #317118
    morruu
    Member
    Post count: 106

    Hi David,

    I understand. I found a solution by myself.

    I used the following code in the template taxonomy-portfolio-category.php (yes I know this should be put in a child theme).

    <?php
     
    global $wp_query; // get the query object
     
    $cat_obj = $wp_query->get_queried_object();
     
    ?>
     
    <p><?php echo get_field('portfolio_long_category_description',$cat_obj->taxonomy.'_'.$cat_obj->term_id); ?></p>

    Best regards
    Morten

    #317141
    David Martin – Support
    Moderator
    Post count: 20834

    Glad you got it working. Yes, you want it within a child theme or as a PHP function.

    Thanks.

    #317192
    morruu
    Member
    Post count: 106

    How can I turn the code into a PHP function? And would it be the best solution?

    Best regards
    Morten

    #317193
    David Martin – Support
    Moderator
    Post count: 20834

    This is more of a StackOverflow question. Taking your above code, you would have something like this in the child theme functions.php file:

    
    function my_custom_function_name() {
    	global $wp_query;
    	$cat_obj = $wp_query->get_queried_object();
    	echo '<p>'. get_field('portfolio_long_category_description', $cat_obj->taxonomy.'_'.$cat_obj->term_id).'</p>';
    }

    You can then add your code to the page my_custom_function_name(); or you can use the WordPress hooks/actions to add the content to the desired location.

    Thanks.

    #317595
    morruu
    Member
    Post count: 106

    Thanks again for your help. The support is awesome 🙂

    Best regards
    Morten

    #317712
    David Martin – Support
    Moderator
    Post count: 20834

    Very glad to help you out where we can.

    If you have found the theme/support useful, we appreciate it if you can leave feedback on our item if you have the time as it really helps us out.

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

You must be logged in and have valid license to reply to this topic.

License required for the following item
Login and Registration Log in · Register