[Resolved] Custom fields

Home Forums Support [Resolved] Custom fields

Home Forums Support Custom fields

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #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.

    #754224
    David
    Staff
    Customer Support

    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.

    #754492
    Kerry

    Thank you!

    #754508
    David
    Staff
    Customer Support

    You’re welcome πŸ™‚

    #957304
    Marcel

    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

    #957611
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Which native GP custom fields exactly?

    You can definitely use ACF in the theme πŸ™‚

    #957629
    Marcel

    I mean native WP custom fields.

    #957861
    Tom
    Lead Developer
    Lead Developer

    What exactly are you wanting to do with them?

    #958053
    Marcel

    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…

    #958533
    Tom
    Lead Developer
    Lead Developer

    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;
    } );
    #958598
    Marcel

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

    #958862
    Tom
    Lead Developer
    Lead Developer

    Glad we could help!

    Always happy to get a little beer/coffee money: https://generatepress.com/ongoing-development/

    Thank you!

    #959432
    Marcel

    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!

    #959778
    Tom
    Lead Developer
    Lead Developer

    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 πŸ™‚

    #959933
    Marcel

    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

Viewing 15 posts - 1 through 15 (of 19 total)
  • You must be logged in to reply to this topic.