• Resolved tatof

    (@tatof)


    Hello!

    Using your plugin for some years now, really happy with it!
    I’m having a problem with prefilling the field in the template function of CPT.

    How are the fields saved? and how can I populate them?
    Below all the options I tried without luck ??

    'template' => array(
    array('tatof/usp', array(
    'data'=> [
    'fontawesome_field' => '<i class="fa-classic fa-light fa-check fa-fw"></i>',
    'fontawesome_field' => 'field_677e951905035',
    ]
    )
    )

    ===== OR =====

    'template' => array(
    array('tatof/usp', array(
    'data'=> [
    'fontawesome_field' => 'fa-classic fa-light fa-check',
    'fontawesome_field' => 'field_677e951905035',
    ]
    )
    )

    ===== OR =====

    'template' => array(
    array('tatof/usp', array(
    'data'=> [
    'fontawesome_field' => 'check',
    'fontawesome_field' => 'field_677e951905035',
    ]
    )
    )

    ===== OR =====

    'template' => array(
    array('tatof/usp', array(
    'data'=> [
    'fontawesome_field' => [
    'element' => '',
    'class' => 'fa-classic fa-light fa-check',
    'id' => 'check',
    'family' => 'classic',
    'style' => 'light',
    'prefix' => 'fa-classic fa-light',
    'hex' => '\\f00c',
    'unicode' => '?',
    ],
    'fontawesome_field' => 'field_677e951905035',
    ]
    )
    )

    ===== OR =====

    'template' => array(
    array('tatof/usp', array(
    'data'=> [
    'fontawesome_field' => ['id' => 'check'],
    'fontawesome_field' => 'field_677e951905035',
    ]
    )
    )
Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter tatof

    (@tatof)

    Can’t edit my post, anyhow there is an error in the code missing an _ in the second data row. This is a copy past error. not live code

    Plugin Author Matt Keys

    (@mattkeys)

    Well I am not 100% sure I follow what you are trying to do. What function exactly are you passing this array of arguments to?

    It might be helpful to create a field and assign it to a post/page. And then go create a new post and select the icon you want, and look at the post meta for that page/custom field in the database to see how it is stored (big json string).

    Thread Starter tatof

    (@tatof)

    Hey Matt,

    In ACF its possible to pre-populate fields in blocks that are part of the CPT.
    So when I make a new CPT “page” there will be standard blocks with populated acf fields.

    Below a little demo how I register a Custom post type with a standard template that is pre-populated. Pre-populate any field works fine, text / image / repeater / etc. But I can’t figure out how to pre-populate the font-awesome field. How do you store the data?

    function tf_post_types(){

    $args = array(
    'labels' => $labels,
    'public' => true,
    //'exclude_from_search' => false,
    //'publicly_queryable' => true,
    'has_archive' => true,
    'hierarchical' => false,
    'query_var' => true,
    'show_in_rest' => true,
    'maybe_has_archive_page' => true,
    'can_export' => true,
    'menu_position' => 3,
    'menu_icon' => 'data:image/svg+xml;base64,' . base64_encode($icon),
    'rewrite' => array( 'slug' => 'woonlocaties','with_front' => false,'feeds' => true ), // URL, Remove slug prefix "blog", Enable feed
    'supports' => array( 'title','editor','thumbnail','revisions','excerpt','author','page-attributes'),
    'taxonomies' => array( 'locaties','woontype' ),
    'template' => array(
    array( 'core/heading', array(
    'level' => 3,
    'placeholder' => 'Schrijf titel',
    'content' => 'This will be pre-populated content',
    )),
    array('core/paragraph', array(
    'placeholder' => 'Schrijf tekst',
    'content' => 'This will be pre-populated content',
    )),
    array( 'tatof/usp',
    array(
    'data' => [
    'block_usps_usps_0_buu_icon' => '<i class="fa-classic fa-light fa-check" aria-hidden="true"></i>',
    '_block_usps_usps_0_buu_icon' => 'field_677e951905035',
    'block_usps_usps_0_buu_title' => 'Uniek voordeel',
    '_block_usps_usps_0_buu_title' => 'field_677e951908b44',
    'block_usps_usps_0_buu_text' => 'Suspendisse dolor nibh, finibus a malesuada quis',
    '_block_usps_usps_0_buu_text' => 'field_677e95190c7a9',
    'block_usps_usps_1_buu_icon' => '<i class="fa-classic fa-light fa-check" aria-hidden="true"></i>',
    '_block_usps_usps_1_buu_icon' => 'field_677e951905035',
    'block_usps_usps_1_buu_title' => 'Uniek voordeel',
    '_block_usps_usps_1_buu_title' => 'field_677e951908b44',
    'block_usps_usps_1_buu_text' => 'Suspendisse dolor nibh, finibus a malesuada quis',
    '_block_usps_usps_1_buu_text' => 'field_677e95190c7a9',
    'block_usps_usps' => 2,
    '_block_usps_usps' => 'field_677e9518d76ae',
    ],
    ),
    ),
    ),
    );
    register_post_type( $customposttype, $args );
    }
    add_action( 'init', 'tf_post_types' );
    Thread Starter tatof

    (@tatof)

    Maybe this screen record helps to explain the problem: https://devtof.nl/prepop.mp4

    Plugin Author Matt Keys

    (@mattkeys)

    I believe you will need to provide the JSON here. An example would be:

    {"family" : "classic", "style" : "regular", "id" : "block-quote", "label" : "Block Quote", "unicode" : "e0b5"}

    If you are unsure how to generate this JSON, it might be helpful to select an icon through an ACF field in one of your posts/pages and then look at the wp_postmeta table to find that value stored as you need it.

    Thread Starter tatof

    (@tatof)

    thanks, will try that next week. (no time now)

    Thread Starter tatof

    (@tatof)

    Yes Json is the fix! thanks ?? works perfectly

    array( 'tatof/usp',
    array(
    'data' => [
    'block_usps_usps_0_buu_icon' => '{"element" : "", "class" : "fa-classic fa-light fa-check", "id" : "check", "family" : "classic", "style" : "light", "prefix" : "fa-classic fa-light", "hex" : "\\f00c", "unicode" : "?"}',
    '_block_usps_usps_0_buu_icon' => 'field_677e951905035',
    ],
    ),
    ),
    • This reply was modified 2 months ago by tatof.
Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.