Digital experiences for all disciplines
New Landing › How can we help? › Themeforest Theme Support › Dante › Show custom field on portfolio category page
New Landing › How can we help? › Themeforest Theme Support › Dante › Show custom field on portfolio category page
- This topic has 7 replies, 2 voices, and was last updated 7 years by David Martin – Support.
-
Posted in: Dante
-
March 13, 2017 at 5:27 pm #317053
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
MortenMarch 13, 2017 at 5:40 pm #317059You 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.
March 13, 2017 at 8:27 pm #317118Hi 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
MortenMarch 14, 2017 at 9:55 am #317141Glad you got it working. Yes, you want it within a child theme or as a PHP function.
Thanks.
March 14, 2017 at 5:02 pm #317192How can I turn the code into a PHP function? And would it be the best solution?
Best regards
MortenMarch 14, 2017 at 5:08 pm #317193This 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.
March 18, 2017 at 10:25 am #317595Thanks again for your help. The support is awesome 🙂
Best regards
MortenMarch 20, 2017 at 1:30 pm #317712Very 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.
-
Posted in: Dante
You must be logged in and have valid license to reply to this topic.