- This topic has 18 replies, 1 voice, and was last updated 2 years, 3 months ago by
Simon.
-
AuthorPosts
-
December 11, 2018 at 1:52 pm #754142
Kerry
Hello,
Looking for some assistance on how to create custom fields. I am working with the Head ON theme from your theme library and I am not sure how to edit the custom fields. Thanks.
December 11, 2018 at 5:06 pm #754224David
StaffCustomer SupportHi there,
in the page editor, check the screen options (top right hand corner) to make sure Custom Fields are checked. Then below you editor you will see the Custom Fields section.
If you are working on the original Site then you should see the pre-populated fields.
December 12, 2018 at 4:56 am #754492Kerry
Thank you!
December 12, 2018 at 5:13 am #754508David
StaffCustomer SupportYou’re welcome π
July 14, 2019 at 3:12 am #957304Marcel
Hello Leo,
Two questions:
1. There is any chance to assign native Generatepress Custom Fields on Woocommerce Products?
2. Could I use Advanced Custom Fields (https://www.advancedcustomfields.com/pro/) instead of native Generatepress Custom Fields?
Thank you!
MarcelJuly 14, 2019 at 9:43 am #957611Tom
Lead DeveloperLead DeveloperHi there,
Which native GP custom fields exactly?
You can definitely use ACF in the theme π
July 14, 2019 at 10:04 am #957629Marcel
I mean native WP custom fields.
July 14, 2019 at 4:21 pm #957861Tom
Lead DeveloperLead DeveloperWhat exactly are you wanting to do with them?
July 15, 2019 at 1:04 am #958053Marcel
Hi, Tom! Actually, I want to use ACF Pro plugin to show some custom fields value on the Woocommerce Product Categories pages. I have created a page hero section for these pages, I have the page title there using {{post_title}}, but under the title, I would like to have these custom fields values, depending on the category. I am a beginner with ACF and it seems to be very difficult to output those custom fields values on woocommerce product category pages. I achieved with success on product pages, using {{custom_field.name}}, but I struggle with taxonomies. I think I have to try more and more and more, the only chance to learn PHP…
July 15, 2019 at 10:07 am #958533Tom
Lead DeveloperLead DeveloperThe
{{custom_field.name}}
template tag will only work on single pages/posts/products. If you’re trying to get custom fields from categories/taxonomies, you need to create a shortcode.For example:
add_shortcode( 'your_shortcode_name', function() { $term = get_queried_object(); $your_field = get_field( 'your_field_name', $term ); return $your_field; } );
July 15, 2019 at 11:24 am #958598Marcel
Tom, may I buy a beer for you? And another one for Leo:). You, guys, are geniuses!!!!
July 15, 2019 at 8:00 pm #958862Tom
Lead DeveloperLead DeveloperGlad we could help!
Always happy to get a little beer/coffee money: https://generatepress.com/ongoing-development/
Thank you!
July 16, 2019 at 9:45 am #959432Marcel
Tom, your beers are in the fridge. Please check it out!
I achieved to output my first custom field value on the front end, following your code. I used a simple text field, made with ACF. Now, I am trying to show a list. For this, I suppose I should use the Repeater Field feature on ACF Pro. After creating the field group, on the Product Category Front End appears the word “Array”, so the shortcode used in the previous scenario doesn’t work anymore.
Should I insert this PHP code somewhere on the taxonomy-product_cat.php?<?php if ( have_rows( 'mtr', $term_id_prefixed ) ) : ?> <?php while ( have_rows( 'mtr', $term_id_prefixed ) ) : the_row(); ?> <?php the_sub_field( 'model' ); ?> <?php endwhile; ?> <?php else : ?> <?php // no rows found ?> <?php endif; ?>
I tried to insert the list on a content page, and it is working. I still struggling with the product category page (Page Hero Content).
Could you guide me for this new scenario? Thank you and enjoy your beer!
July 16, 2019 at 5:36 pm #959778Tom
Lead DeveloperLead DeveloperThank you! Really appreciate it.
If your custom field is an array, you can do this:
add_shortcode( 'your_shortcode_name', function() { ob_start(); $term = get_queried_object(); $your_field = get_field( 'your_field_name', $term ); foreach( $your_field as $field ) { echo $field; } return ob_get_clean(); } );
Let me know if that helps or not π
July 17, 2019 at 12:59 am #959933Marcel
Nope. I have this warning on the front end: “Invalid argument supplied for foreach() in E:\xampp\htdocs\testsite\wp-content\themes\generatepress_child\functions.php on line 37”.
Screenshot attached with line 37: https://www.screencast.com/t/lEvXHH9hUu -
AuthorPosts
- You must be logged in to reply to this topic.