Site logo

Archived topic

Custom fields

18 replies · Started by Kerry on December 11, 2018

Viewing posts 1–15 of 19

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.

Hi 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.

Thank you!

You're welcome :)

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!
Marcel

Hi there,

Which native GP custom fields exactly?

You can definitely use ACF in the theme :)

I mean native WP custom fields.

What exactly are you wanting to do with them?

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...

The {{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;
} );

Tom, may I buy a beer for you? And another one for Leo:). You, guys, are geniuses!!!!

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!

Thank 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 :)

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

This archived topic is closed to new replies.