Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

topic

  • Unread

    Using post types as part of another taxonomy

    Hi all,

    I’ve searched on the forum and cannot find an answer to my question. So I hope someone can help me.

    I have a post type called Technologies. In it I have posts that describe each technology that I have an interest in, and it becomes a landing page.

    Here’s an example:
    I have one post each for the following technologies:
    AI
    ChatGPT
    LLM

    I use these posts for landing pages such as:
    example.com/technologies/ai
    example.com/technologies/chatgpt
    example.com/technologies/llm

    Now, I want to associate these technologies with articles (using a post type articles) that I write regarding these technologies. I would rather not have a custom field call technology in these posts, because that means I have to manage these technologies in two places as I add or delete technologies that I want to write about.

    Is there a way in my post type articles that can have the various technologies I have defined in my technologies post types?

    I hope I’ve explained this correctly and clearly.

    Thanks in advance.

    Ben

  • Solved

    How can I manually change a datetime picker value

    I have a hidden datetime field in a repeater. When a repeater row is duplicated, I would like to change the datetime value. I have tried using acf.getField and then setting
    field.val( new-date-string)
    also
    jQueryElement.attr('value', new-date-string)
    and
    jQueryElement.val(new-date-string)
    finally
    jQueryElement.datepicker('setDate', new-date-string)
    none of these seem to alter the datetime value. I’m assuming maybe I’m accessing the wrong element but I’m not sure which one I should get?

  • Unread

    Auto collapse all flexible content fields that are nested within a repeater

    I want to automatically collapse all flexible content fields that are nested within a repeater field.

    I am building a restaurant menu that is quite large and each items has multiple pricing options that depend on quantity or toppings.

    I have managed to do this using the flexible content field type that is nested under a repeated field and it works well except for one issue.

    As I mentioned, the menu is quite large and each item itself has 5 fields so it takes up a lot of vertical space as all flexible content fields are opened by default and need to be manually collapsed by clicking on the inverted triangle icon (click to toggle option).

    Is there a way these fields are close by default? Say, as soon as the content is filled-in they automatically collapse instead of having to manually close them?

  • Unread

    update_field(‘location’, $new_location, $product_id);

    I’m struggling getting a field value updated using a plugin.

    Can anyone tell me what i’m doing wrong when calling to the update_field function?

    Thanks

    THis is the simple plugin code

    // Adding option to admin panel
    add_action(‘admin_menu’, ‘ple_add_admin_menu’);

    function ple_add_admin_menu() {
    add_menu_page(
    ‘Product Location Editor’,
    ‘Location Editor’,
    ‘manage_woocommerce’,
    ‘product-location-editor’,
    ‘ple_admin_page_content’,
    ‘dashicons-location-alt’,
    20
    );
    }

    // Function to create the admin page
    function ple_admin_page_content() {
    ?>
    <div class=”wrap”>
    <h1>Change Location of Product</h1>
    <form method=”post” action=””>
    <label for=”product_search”>Search product by SKU or description:</label><br>
    <input type=”text” name=”product_search” id=”product_search” placeholder=”input SKU o description” required>
    <input type=”submit” value=”Search Product” class=”button button-primary”>
    </form>

    <?php
    if (!empty($_POST[‘product_search’])) {
    ple_search_and_update_product(sanitize_text_field($_POST[‘product_search’]));
    }
    ?>
    </div>
    <?php
    }

    // Function to search the product
    function ple_search_and_update_product($search_term) {
    // Buscar productos por SKU o descripción
    $args = array(
    ‘post_type’ => ‘product’,
    ‘s’ => $search_term,
    ‘posts_per_page’ => 10,
    );

    $products = new WP_Query($args);

    if ($products->have_posts()) {
    echo ‘<h2>Resultados de la búsqueda:</h2>’;
    while ($products->have_posts()) {
    $products->the_post();
    $product_id = get_the_ID();
    $product_name = get_the_title();
    $location = get_field(‘location’, $product_id);

    echo ‘<form method=”post” action=””>’;
    echo ‘<p>‘ . esc_html($product_name) . ‘</p>’;
    echo ‘<input type=”hidden” name=”product_id” value=”‘ . esc_attr($product_id) . ‘”>’;
    echo ‘<label for=”new_location”>Location actual: ‘ . esc_html($location) . ‘</label><br>’;
    echo ‘<input type=”text” name=”new_location” placeholder=”Nuevo Location” required>’;
    echo ‘<input type=”submit” value=”Actualizar Location” class=”button button-primary”>’;
    echo ‘</form>’;
    echo ‘<hr>’;
    }
    wp_reset_postdata();
    } else {
    echo ‘<p>The search did not provide results.</p>’;
    }
    }

    // Function to update field value “location”
    add_action(‘admin_post_ple_update_location’, ‘ple_update_location’);

    function ple_update_location() {
    if (!empty($_POST[‘product_id’]) && !empty($_POST[‘new_location’])) {
    $product_id = intval($_POST[‘product_id’]);
    $new_location = sanitize_text_field($_POST[‘new_location’]);

    // Update sentence
    update_field(‘location’, $new_location, $product_id);
    //update_post_meta($product_id, ‘location’, $new_location);

    wp_redirect(admin_url(‘admin.php?page=product-location-editor&updated=true’));
    exit;
    }
    }

  • Helping

    Best practices for hiding a custom field if no value is assigned

    I’m building a site with ACF Pro and using Bricks as my page builder and query system. I’ve created a custom post type for products, and I have a field set with 8 attributes. Most products will not have values for all 8 attributes for a variety of reasons.
    What is a good approach that would allow me to only show attributes that contain a value on the product detail page? I’m sort of struggling to understand the best way to solve this.

    thanks!

  • Unread

    relationship for taxonomy get current this taxonomy post

    Hi team,

    I have a post_type = project
    and a taxonomy for post_type = project_page
    – Now I create a relationship name = taxpage_order for taxonomy project_page

    how to: in project_page load current post_type = project of taxonomy

    my code get current: post of taxonomy: but not true

    
    function vnt_taxpage_order( $args, $field, $post_id ) {
        $queried_object = get_queried_object();
    
        if ( isset( $queried_object->taxonomy ) && $queried_object->taxonomy === 'project_page' ) {
            $term_id = $queried_object->term_id;
    
            $args['tax_query'] = array(
                array(
                    'taxonomy' => 'project_page',
                    'field'    => 'term_id',
                    'terms'    => $term_id,
                ),
            );
        }
    
        return $args;
    }
    add_filter( 'acf/fields/relationship/query/name=taxpage_order', 'vnt_taxpage_order', 10, 4 );
    

    Any idea for my case?
    Thanks team!

  • Unread

    New field causing error

    I feel like I’m missing something really basic here:

    – I have a “Hero” group that I’ve added to the homepage field set as a clone
    – I’ve now cloned the same group to my general Page fieldset, so I can use it on all pages.
    – Now, pages (there are a lot of them!) are consistently throwing the following error:

    Warning: Trying to access array offset on value of type null in /Users/dafydd/Local Sites/cymdeithas-madog/app/public/wp-content/themes/cm24/cm24_inc/hero.php on line 3

    – I know this is because the hero field hasn’t been added to these pages’ database entries.
    – I can resolve this issue by entering the edit interface for each page and hitting Update, which adds the Hero entry to the page’s database entry. Bulk editing doesn’t work.

    I’m using the following to get the Hero group:

    $hero = get_field(‘hero’)[“hero”];

    My questions:

    1. Is there a way to update all pages at once to register the new field?
    2. Barring that, is there a way to allow get_field() to fail without throwing an error?

    Grateful for any advice here!

  • Unread

    A genuine question regard payment methods…

    Greetings ACF team,

    Since ACF Pro is an industry standard plugin or software (according to what I have read) in wordpress world, how does it take to ACF Pro team to implement or bring other payment options for non-US user to purchase your product beside credit card method?

  • Helping

    Migrated repeater fields visible in front end, but not when editing block

    I submitted a ticket to what now seems to be WP Engine support to no avail, so will post here just in case!

    I have a block called Link List, which well is just a list of links. It was a repeater for manually entered link items but it was updated to include existing site content as well. I seem to have successfully migrated the fields in the old repeater to the fields in the updated repeater, I can see them in block preview and when viewing the block on the front end. However, when editing the block, there are no populated fields to edit.

    Old json – repeater field with three subfields (subhead, url, short_description):

    {
    "key": "field_64837282e5ad9",
    "label": "Old Link List Items",
    "name": "items",
    "aria-label": "",
    "type": "repeater",
    "instructions": "",
    "required": 0,
    "conditional_logic": 0,
    "wrapper": {
    "width": "",
    "class": "",
    "id": ""
    },
    "layout": "block",
    "pagination": 0,
    "min": 0,
    "max": 0,
    "button_label": "Add Row",
    "rows_per_page": 20,
    "sub_fields": [
    {
    "key": "field_6483729ae5ada",
    "label": "Old Subhead",
    "name": "subhead",
    "aria-label": "",
    "type": "text",
    "instructions": "",
    "required": 1,
    "conditional_logic": 0,
    "wrapper": {
    "width": "",
    "class": "",
    "id": ""
    },
    "default_value": "",
    "maxlength": "",
    "placeholder": "",
    "prepend": "",
    "append": "",
    "parent_repeater": "field_64837282e5ad9"
    },
    {
    "key": "field_64837357e5adc",
    "label": "Old URL",
    "name": "url",
    "aria-label": "",
    "type": "url",
    "instructions": "",
    "required": 0,
    "conditional_logic": 0,
    "wrapper": {
    "width": "",
    "class": "",
    "id": ""
    },
    "default_value": "",
    "placeholder": "",
    "parent_repeater": "field_64837282e5ad9"
    },
    {
    "key": "field_648372afe5adb",
    "label": "Old Short Description",
    "name": "short_description",
    "aria-label": "",
    "type": "textarea",
    "instructions": "",
    "required": 0,
    "conditional_logic": 0,
    "wrapper": {
    "width": "",
    "class": "",
    "id": ""
    },
    "default_value": "",
    "maxlength": 155,
    "rows": "",
    "placeholder": "",
    "new_lines": "",
    "parent_repeater": "field_64837282e5ad9"
    }
    ]
    },

    New json – repeater with three sub fields (entry_method, custom_item, existing_item), the custom_item containing the original three item fields (subhead, url, short_description) from above.

    {
    "key": "field_66b4df4663782",
    "label": "Link List Items",
    "name": "link_list_items",
    "aria-label": "",
    "type": "repeater",
    "instructions": "",
    "required": 0,
    "conditional_logic": 0,
    "wrapper": {
    "width": "",
    "class": "",
    "id": ""
    },
    "layout": "row",
    "pagination": 0,
    "min": 0,
    "max": 0,
    "collapsed": "",
    "button_label": "Add Link Item",
    "rows_per_page": 20,
    "sub_fields": [
    {
    "key": "field_66b11540e682f",
    "label": "Entry Method",
    "name": "entry_method",
    "aria-label": "",
    "type": "select",
    "instructions": "",
    "required": 0,
    "conditional_logic": 0,
    "wrapper": {
    "width": "",
    "class": "",
    "id": ""
    },
    "choices": {
    "custom": "Custom URL",
    "existing": "Existing Page Content"
    },
    "default_value": "custom",
    "return_format": "value",
    "multiple": 0,
    "allow_null": 0,
    "ui": 0,
    "ajax": 0,
    "placeholder": "",
    "parent_repeater": "field_66b4df4663782"
    },
    {
    "key": "field_6758a9a91df40",
    "label": "Custom Link List Item",
    "name": "custom_item",
    "aria-label": "",
    "type": "group",
    "instructions": "",
    "required": 0,
    "conditional_logic": [
    [
    {
    "field": "field_66b11540e682f",
    "operator": "==",
    "value": "custom"
    }
    ]
    ],
    "wrapper": {
    "width": "",
    "class": "",
    "id": ""
    },
    "layout": "block",
    "sub_fields": [
    {
    "key": "field_6758a8101df3e",
    "label": "Subhead",
    "name": "subhead",
    "aria-label": "",
    "type": "text",
    "instructions": "",
    "required": 1,
    "conditional_logic": 0,
    "wrapper": {
    "width": "",
    "class": "",
    "id": ""
    },
    "default_value": "",
    "maxlength": "",
    "placeholder": "",
    "prepend": "",
    "append": ""
    },
    {
    "key": "field_66b4e13bd37ad",
    "label": "URL",
    "name": "url",
    "aria-label": "",
    "type": "url",
    "instructions": "",
    "required": 1,
    "conditional_logic": 0,
    "wrapper": {
    "width": "",
    "class": "",
    "id": ""
    },
    "default_value": "",
    "placeholder": ""
    },
    {
    "key": "field_66b4e13bd37ae",
    "label": "Short Description",
    "name": "short_description",
    "aria-label": "",
    "type": "textarea",
    "instructions": "",
    "required": 0,
    "conditional_logic": 0,
    "wrapper": {
    "width": "",
    "class": "",
    "id": ""
    },
    "default_value": "",
    "maxlength": 155,
    "rows": "",
    "placeholder": "",
    "new_lines": ""
    }
    ],
    "parent_repeater": "field_66b4df4663782"
    },
    {
    "key": "field_66b1161ae6830",
    "label": "Existing Link List Item",
    "name": "existing_item",
    "aria-label": "",
    "type": "relationship",
    "instructions": "",
    "required": 0,
    "conditional_logic": [
    [
    {
    "field": "field_66b11540e682f",
    "operator": "==",
    "value": "existing"
    }
    ]
    ],
    "wrapper": {
    "width": "",
    "class": "",
    "id": ""
    },
    "post_type": "",
    "post_status": "",
    "taxonomy": "",
    "filters": [
    "search",
    "post_type",
    "taxonomy"
    ],
    "return_format": "id",
    "min": "",
    "max": 1,
    "elements": "",
    "bidirectional": 0,
    "bidirectional_target": [],
    "parent_repeater": "field_66b4df4663782"
    }
    ]
    }

    PHP – migrating the old item fields into new Link List Items > Custom Item

    $old_items = get_field('items') ?: [];
    $link_list_items = get_field('link_list_items', $post_id) ?: [];

    if ($old_items) {
    foreach ($old_items as $old_item) {
    $is_duplicate = false;
    foreach ($link_list_items as $existing_item) {
    if (
    $existing_item['entry_method'] === 'custom' &&
    $existing_item['custom_item']['subhead'] === $old_item['subhead'] &&
    $existing_item['custom_item']['url'] === $old_item['url'] &&
    $existing_item['custom_item']['short_description'] === $old_item['short_description']
    ) {
    echo '<p>Duplicate found:</p>

    ';
                    var_dump($old_item);
                    echo '

    ';
    $is_duplicate = true;
    break;
    }
    }

    // If not a duplicate, add to the new structure
    if (!$is_duplicate) {
    echo '<p>Adding new item:</p>

    ';
                var_dump($old_item);
                echo '

    ';
    $link_list_items[] = [
    'entry_method' => 'custom',
    'custom_item' => [
    'subhead' => $old_item['subhead'],
    'url' => $old_item['url'],
    'short_description' => $old_item['short_description'],
    ],
    'existing_item' => null,
    ];
    }
    }

    echo '<p>New link_list_items array to update:</p>

    ';
        var_dump($link_list_items);
        echo '

    ';

    // Update the field with the current + migrated items
    $update_result = update_field('link_list_items', $link_list_items, $post_id);

    // // Check if the update was successful
    if ($update_result) {
    echo '<p>Field updated successfully.</p>';
    } else {
    echo '<p>Failed to update field.</p>';
    }
    }

    Just to reiterate, after running the migration script I can now see the old field data in the new fields on the front end, but if I edit the Link List block it’s as if there is no content.

    Any help troubleshooting this would be appreciated, thanks!

  • Unread

    How to show an auto populated field data?

    I am trying to show an auto-populated field. I have generated it using load_field filter.

    I’ve auto-populated a textfield pmname using User select_a_project_manager field. I retrieved display_name and It auto-populated the pmname field. It’s working. Code below-

    function pm_load_field( $field ) {
    	
    	$user = get_field("select_a_project_manager");
    	if( $user ): ?>
    	<div class="author-box">
    		<h3><?php $user['display_name']; ?></h3>
    	</div>
    	<?php endif;	
    	 $field['value'] = $user['display_name'];
    	 return $field;
    }

    add_filter('acf/load_field/name=pmname', 'pm_load_field');

    The problem is I cannot show the pmname field in the template (In my case Elementor). It doesn’t return anything. So I assume the the field value is not saved. How can I save it?

  • Unread

    Meta_query for nested repeater field values in a cpt.

    I have a cpt as a template for courses. Each course template can contain several courses. The courses are recorded in a repeater, which in turn contains a repeater for dates.
    I need to query all course template that have a course without a date. My existing code to query only the first course of each template is:

    $args = array(
    'post_type' => 'kurs-vorlage',
    'posts_per_page' => -1,
    'meta_query' => array(
    array(
    'key' => 'kurse_repeater_0_daten_0_datum',
    'compare' => '=',
    'value' => '',
    ),
    ),
    );

    Customization with the $ sign returns no results:
    $args = array(
    'post_type' => 'kurs-vorlage',
    'posts_per_page' => -1,
    'meta_query' => array(
    array(
    'key' => 'kurse_repeater_$_daten_0_datum',
    'compare' => '=',
    'value' => '',
    ),
    ),
    );

    How can the meta-query be changed to check all courses in a template for an empty first date field? Thanks!

  • Unread

    Removing the CPT slug

    Just a question. I’m trying to remove the CPT slug from the URL but I don’t want to use another plugin for a such simply task. Any advice please?

    I found on some forum to set the user permalink and replace the slug with “/”. But this doesn’t work. So maybe to add some code to advanced scripts. Thank you.

  • Helping

    Possible to link custom taxonomy to existing product page rather than archive?

    Hey everyone, hoping you can lend some advice if possible. I’m pretty new to website development and coding, so am pretty out of my element here! This might be very easy to do, so apologise for my ignorance, but I’d appreciate the clarification/help if possible. Thanks in advance!

    Basically, I’m building a website (using Elementor Pro) for a forthcoming magazine that’s going to publish several issues a year. There are going to be a number of Loop Items on the site that cycle through the magazine’s posts across various categories, and within each Loop Item template is a Post Info widget that ideally needs to list the author name, genre of post and the issue number that post can be found within. Obviously the first two are already present, but I figured I needed ACF to create the custom taxonomy of Issue Number.

    Unlike the other taxonomies for author, genre etc., what I basically want to happen regarding this custom taxonomy is that, instead of triggering a query and taking you through to a filtered archive of posts at, e.g. ‘[website address].com/issue-number/issue-1’ etc., I want clicking on this issue number to actually take you to the direct product page where you can buy that issue, e.g. (in my case) ‘[website address].com/shop/standalone-issues/issue-1’. Is this viable, and if so, how would I go about implementing it? Much appreciated!

  • Unread

    Solution share : nested tabs

    I was trying to organize my configuration fields in option page in multiple depths of tabs but found that trying to close a nested tabgroup to add nother tab in parent tabgroup was impossible, like exposed by @tdmalone in this thread.

    Also, using group field is not an option : my code is already written and I don’t want to have to handle useless additional array dimensions or non unique field names, like suggested by @jackfowler.

    So I tried to fix the issues caused by poor DOM tree the code of ACF generates.

    1. Add the tab field a custom tabgroupend setting:

    add_action( 'acf/render_field_settings/type=tab', function( array $field ) {
    acf_render_field_setting( $field, [
    'label' => __( 'End of tab group', 'mydom' ),
    'instructions' => '', // Tooltip
    'hint' => '',
    'type' => 'true_false',
    'name' => 'tabgroupend',
    'ui' => 1,
    'class' => 'acf-field-object-true-false-ui',
    ], global: false );

    And set a custom class on the tabs where this setting is enabled:

    add_filter( 'acf/prepare_field', function( array $field ) {
    if( ! empty( $field['tabgroupend'] ) ) {
    $field['class'] .= ' acf-tabgroupend';
    }

    return $field;
    } );

    This results to add acf-tabgroupend on tab links.

    2. Set up a nested tabs structure with such logic :

    • Tab 1
    • Tab 2
      • Tab 2.1 <– enable native endpoint setting on this one
      • Tab 2.2
      • Tab 2.3 <– enable custom tabgroupend setting on this one
    • Tab 3

    3. Now script a bit through in a JS loaded on backend only :
    (written in ES6)

    window.acf?.addAction('ready', function() { // This allows to delay a bit after ACF other actions execution

    if( ! acfTabgroupendEls.length ) {
    return
    }

    /**
    * Move acf-tabgroupend subsequent tabs to upper tabgroup
    */
    acfTabgroupendEls.forEach( tabpanel => {
    const ownTab = document.querySelector(
    .acf-tab-button[data-key="${tabpanel.dataset.key}"] ).parentNode // li
    const ownTabWrap = ownTab.closest( '.acf-tab-wrap' )

    // Tabs to move
    let tabsToMove = []
    let p = false // used to flag the tab
    ownTabWrap.querySelectorAll( 'li' ).forEach( li => {
    if( ! p ) {
    if( li.isSameNode( ownTab ) ) {
    p = true
    }

    return
    }

    tabsToMove.push( li )
    } )

    // Find tab group to move to
    let elem = ownTabWrap.previousElementSibling
    let secu = 0
    let parentTabWrap

    // Loop over the previous siblings to find possible parent in previous tabwraps
    while( elem && secu < 1000 ) {
    secu++

    if( elem.matches( '.acf-tab-wrap' ) ) {
    // tabwrap has an explicit end: continue to search up
    if( ! elem.querySelector( '.acf-tabgroupend' ) ) {
    parentTabWrap = elem
    break
    }
    }

    elem = elem.previousElementSibling
    }

    // No parent found: abort
    if( ! parentTabWrap ) {
    return
    }

    const newSiblingsTabs = parentTabWrap.querySelectorAll( 'li' )

    // Move tabs to parent
    tabsToMove.forEach( tab => {
    parentTabWrap.childNodes[0].appendChild( tab )
    } )

    } )

    /**
    * Rework tabs showing/hiding
    */
    document.querySelectorAll( '.acf-fields' ).forEach( acfFieldsEl => {
    const childrenEls = Array.from( acfFieldsEl.childNodes ).filter( x => x.nodeType == Node.ELEMENT_NODE )

    // No children elements: skip
    if( ! childrenEls.length ) {
    return
    }

    let tabTree = {}
    let tabs = {}
    let depth = 0
    let currentKey

    childrenEls.forEach( childEl => {
    if( childEl.matches( '.acf-tab-wrap' ) ) {
    childEl.querySelectorAll( '.acf-tab-button[data-key]' ).forEach( tabBtn => {
    if( tabBtn.dataset.endpoint == '1' ) {
    depth++
    }

    tabs[tabBtn.dataset.key] = {
    depth: depth,
    element: tabBtn.parentNode,
    children: [],
    }

    if( tabBtn.matches( '.acf-tabgroupend' ) ) {
    depth--
    }
    } )
    }
    } )

    // No tabgroup in there: skip
    if( _.isEmpty( tabs ) ) { // use of Lodash isEmpty helper, build your own if you prefer
    return
    }

    // Store children with each parent tab
    childrenEls.forEach( childEl => {
    if( childEl.matches( '.acf-field-tab[data-key]' ) ) {
    currentKey = childEl.dataset.key
    }
    else if( currentKey ) {
    tabs[currentKey].children.push( childEl )
    }
    } )

    Object.values( tabs ).forEach( tab => {
    tab.element.addEventListener( 'click', ( e ) => {
    Object.values( tabs ).forEach( t => {
    // Different depth: skip
    if( t.depth != tab.depth ) {
    return
    }

    const activate = t.element.isSameNode( tab.element )

    t.element.classList.toggle( 'active', activate )

    t.children.forEach( child => {
    child.classList.toggle( 'acf-hidden', ! activate )

    if( ! activate ) {
    child.setAttribute( 'hidden', '' )
    }
    else {
    child.removeAttribute( 'hidden' )
    }
    } )
    } )
    } )
    } )
    } )

    /**
    * Fixes wrong visible tabs at load
    */
    document.querySelectorAll( '.acf-tab-wrap .active' ).forEach( tabBtn => tabBtn.dispatchEvent( new MouseEvent( 'click' ) ) )
    }

    Worth to say that this solution will let unchanged the field groups where you did not enable tabgroupend custom setting on any tab.

  • Solved

    get_field() for separate groups shows value from the same group??

    I have 2 groups within my block

    It all displays correctly and saves correctly. No issues.
    However, in my template I try to get the values and I get strange issues.

    
    var_dump(get_field('group_four_square_main_square_background'));
    var_dump(get_field('group_four_square_main_square_cta'));
    

    Both return the SAME values!
    var_dump

    Why?

    
    function init_four_square_fields() {
      acf_add_local_field_group([
        'key' => 'group_four_square',
        'title' => 'Four Square',
        'fields' => [
          [
            'key' => 'field_four_square_main_square_title',
            'label' => 'Title',
            'name' => 'four_square_main_square_title',
            'type' => 'text',
            'prefix' => '',
            'instructions' => '',
            'required' => 0,
            'conditional_logic' => 0,
            'wrapper' => [
              'width' => '100',
              'class' => '',
              'id' => '',
            ],
            'default_value' => '',
            'placeholder' => '',
            'prepend' => '',
            'append' => '',
            'maxlength' => '',
            'readonly' => 0,
            'disabled' => 0,
          ],
          [
            'key' => 'field_four_square_main_square_description',
            'label' => 'Description',
            'name' => 'four_square_main_square_description',
            'type' => 'textarea',
            'prefix' => '',
            'instructions' => '',
            'required' => 0,
            'conditional_logic' => 0,
            'wrapper' => [
              'width' => '100',
              'class' => '',
              'id' => '',
            ],
            'default_value' => '',
            'placeholder' => '',
            'prepend' => '',
            'append' => '',
            'maxlength' => '',
            'readonly' => 0,
            'disabled' => 0,
          ],
          [
            'key' => "group_four_square_main_square_cta",
            'label' => 'CTA',
            'type' => 'group',
            'layout' => 'block',
            'sub_fields' => [
              [
                'key' => 'link',
                'name' => 'link',
                'label' => 'Link',
                'type' => 'link',
                'instructions' => '',
                'required' => 0,
                'conditional_logic' => 0,
                'wrapper' => [
                  'width' => '50',
                  'class' => '',
                  'id' => '',
                ],
                'return_format' => 'array',
                'wpml_cf_preferences' => 2,
                'acfml_field_group_mode' => 'advanced',
              ],
              [
                'key' => 'class',
                'name' => 'class',
                'label' => 'Class',
                'type' => 'text',
                'required' => 0,
                'conditional_logic' => 0,
                'wrapper' => [
                  'width' => '50',
                  'class' => '',
                  'id' => '',
                ],
                'wpml_cf_preferences' => 0,
                'maxlength' => '255',
              ]
            ]
          ],
          [
            'key' => "group_four_square_main_square_background",
            'label' => 'Main Square Background',
            'type' => 'group',
            'layout' => 'block',
            'sub_fields' => [
              [
                'key' => 'type',
                'label' => 'Type',
                'name' => 'type',
                'type' => 'radio',
                'instructions' => '',
                'required' => 0,
                'conditional_logic' => 0,
                'wrapper' => [
                  'width' => '50',
                  'class' => '',
                  'id' => '',
                ],
                'choices' => [
                  'image' => 'Image',
                  'video' => 'Video',
                  'color' => 'Color',
                  // 'embed' => 'Embed video',
                ],
                'allow_null' => 0,
                'other_choice' => 0,
                'default_value' => 'color',
                'layout' => 'horizontal',
                'return_format' => 'value',
                'save_other_choice' => 0,
                'wpml_cf_preferences' => 0,
                'acfml_field_group_mode' => 'advanced',
              ],
              [
                'key' => 'image',
                'label' => 'Image',
                'name' => 'image',
                'type' => 'image',
                'instructions' => '',
                'required' => 0,
                'conditional_logic' => [
                  [
                    [
                      'field' => 'type',
                      'operator' => '==',
                      'value' => 'image',
                    ],
                  ],
                ],
                'wrapper' => [
                  'width' => '50',
                  'class' => '',
                  'id' => '',
                ],
                'return_format' => 'array',
                'preview_size' => 'full',
                'library' => 'all',
                'min_width' => '',
                'min_height' => '',
                'min_size' => '',
                'max_width' => '',
                'max_height' => '',
                'max_size' => '',
                'mime_types' => '',
              ],
              [
                'key' => 'video',
                'label' => 'Video',
                'name' => 'video',
                'type' => 'file',
                'instructions' => '',
                'required' => 0,
                'conditional_logic' => [
                  [
                    [
                      'field' => 'type',
                      'operator' => '==',
                      'value' => 'video',
                    ],
                  ],
                ],
                'wrapper' => [
                  'width' => '50',
                  'class' => '',
                  'id' => '',
                ],
                'return_format' => 'array',
                'library' => 'all',
                'min_size' => '',
                'max_size' => '',
                'mime_types' => '',
              ],
              [
                'key' => 'color',
                'name' => 'color',
                'type' => 'select',
                'choices' => [],
                'conditional_logic' => [
                  [
                    [
                      'field' => 'type',
                      'operator' => '==',
                      'value' => 'color',
                    ],
                  ],
                ],
              ]
            ]
          ],
        ],
        'location' => [
          [
            [
              'param' => 'block',
              'operator' => '==',
              'value' => 'acf/four-square',
            ],
          ],
        ],
        'menu_order' => 0,
        'position' => 'normal',
        'style' => 'default',
        'label_placement' => 'top',
        'instruction_placement' => 'label',
        'hide_on_screen' => '',
      ]);
    }
    
    add_action('acf/init', 'init_four_square_fields');
    
  • Unread

    Set default values to dynamic

    Hey there! Long question taken short:

    I want to be able to only edit from the admin interface so I dont need to enter a page to edit the fields as I wont need to do that, Im interessted in having the default values to be set as the text / values to be shown always.

    Any ideas people?, I dont know much about coding, just a bit.

  • Helping

    Example preview of repeater

    Hi!
    I have repeater list with text fields list-text
    How to fill-in example for repeater in block.json?

    I tried these variants:

      "example": {
        "attributes": {
          "data": {
            "list": [
              [
                ["list-text", "Element 1"]
              ],
              [
                ["list-text", "Element 2"]
              ],
              [
                ["list-text", "Element 3"]
              ]
            ]
          }
        }
      }
      "example": {
        "attributes": {
          "data": {
            "list": [
              {
                "list-text": "Element 1"
              },
              {
                "list-text": "Element 2"
              },
              {
                "list-text": "Element 3"
              }
            ]
          }
        }
      }

    But it doesn’t work.

  • Solving

    Returning items (Settings page) category

    Hello,
    I’m currently working on the following within a client’s website.

    In the “Page settings” I have configured the ability to insert photos that can be tagged. I did not deliberately choose the “Gallery” model, as it is not possible to add labels to these photos. That’s why I chose a custom gallery with labels. At the same time, these labels can be managed by the client himself, so he can create a new category at any time, without my intervention.

    The categories have this hierarchy:
    – 1) Main categories (e.g. CABELS)
    – 2) Subcategories (e.g. SMALL, LARGE)

    I was able to use foreach to get a listing of the subcategories as well, but I don’t know how I can now get all the items that have that category.

    Could I ask for a foreach that takes as input the id or name of the subcategory(“label”) and returns me all the items that are labelled this way?

    I am sending the actual code that I found publicly somewhere on the forum and I need to modify it to get the URL of the IMAGE, DESCRIPTION (ACF field) + URL (ACF field). The code can be completely different, I just need to go through all the existing subcategories (level 2).

    
       <div class="container-fluid">
            <div class="row">
                <div class="tab-content" id="pills-tabContent">
                    <?php /** Loop through every term */
                    foreach ($terms as $term) {
                        /** Skip term if it has children */
                        if ($term->parent) {
                            continue;
                        }
                        if ($hierarchy[$term->term_id]) {
                            foreach ($hierarchy[$term->term_id] as $child) {
                                /** Get the term object by its ID */
                                $child = get_term(
                                    $child,
                                    "kategorie--inspirace"
                                ); ?>
                    <div class="tab-pane fade show" id="pod<?php echo $child->slug; ?>" role="tabpanel"
                        aria-labelledby="pod<?php echo $child->slug; ?>-tab">
    
                       <strong> In this section I need to get the url to the image in the settings page, description and link.</strong>
    
                    </div>
                    <?php
                            }
                        }
                    } ?>
                </div>
            </div>
        </div>
    

    I am sending a screenshot in the attachment:
    – settings page
    – acf field configuration in settings page

    Thank you
    Robert Glogowski

  • Solved

    Show custom taxonomy on custom post type page

    Hi all,

    Would love some help on a website I’m currently building because I seem to not get something to work. The website has a custom post type ‘evenement‘. I have created a custom taxonomy ‘locatie‘ and last but not least I have made a Field group item ‘evenement_locatie‘, linked to the custom taxonomy.

    I made a template for that show’s a single evenement post, that show’s the custom fields which I get with this code


    <p><?php the_field("event_startdate"); ?><br> om <?php the_field("event_starttime"); ?></p>

    This works fine for all fields, however I can’t seem to load the custom taxomony, and I tried all codes that I could find online. This is the code I’m currently using:

    <?php
    $term = get_field('evenement_locatie'); if( $term ): ?> <h2><?php echo esc_html( $term->name ); ?>test</h2> <p><?php echo esc_html( $term->description ); ?></p> <?php endif; ?>

    And I have also tried


    <?php echo get_field('evenement_locatie', get_queried_object()); ?>

    Also tried to use the get_term function, but I can’t figure out how to get it working.
    I also trying using get_field(‘locatie’) and that does not work as well.

    My goal is to show the taxonomy title, and the description, but I’ve tried for hours now to get something. Also the WP_DEBUG is not giving me any error’s as well, so don’t know how to continue.

    Any tips or tricks?
    Thanks in advance!

  • Unread

    New query with multiple fields

    Hey,

    I found a couple of posts here, but I’m not too wise about it.
    We have an options box for each of my CPTs, and in the archive users can filter based on those values. But some of them are similar and I would need to merge them in the filter and I’m not sure what is the best way. I use Bricks, so I always just enter the meta key in the filter and get the values.

    I am posting a screen below that better explains what I need. Can you advise me what the code should look like?

    Thanks!

  • Unread

    ACF Repeater with different odd/even rows [Solved]

    I wanted to add different AOS (Animate On Scroll) codes to odd and even rows. I was able to get this working, and I wanted to share it with others who wish to do the same.

    Theme: Bootstrap-based
    Repeater: content_by_paragraph
    Repeater field: paragraph (editor)

    <?php $row = 0;?>
    
    <div id="container-content" class="container">
        <div class="row">
            <div class="col-md-10 offset-md-1 py-5">
                    <?php
                    if( have_rows('content_by_paragraph') ):
    
                        while ( have_rows('content_by_paragraph') ) : the_row() ?>
    
    <?php if ($row % 2 === 0) :?>
    
    <div class="p_1" data-aos="fade-left"><?php the_sub_field('paragraph'); ?></div>
    
    <?php else: ?>
    
    <div class="p_2" data-aos="fade-right"><?php the_sub_field('paragraph'); ?></div>
    
                <?php endif; ?>
    
    <?php $row++; ?>
    
                     <?php endwhile;
                    else :
                    endif;
                    ?>
            </div>
        </div>
    </div>
  • Unread

    packaging block.json renderTemplate in basic webpack setup

    I am using ACF blocks with “block.json”, where my blocks are compiled from a /source directory to a /build directory, where they are registered. I’m using a relatively default variation of ‘@wordpress/scripts/config/webpack.config for compiling/building.

    My issue is that “render.php” will not copy over into my build directory unless I include the “render” property ("render": "file:./render.php). But if I include that, then the render template is interpreted as a standard block render template and not an ACF template.

    Is there are straightforward workaround for this, or is this something I need to work out manually in my “webpack.config.js”? I’m pretty new to webpack configuration, and all I can think of is to create a new entry point in modules.exports for each of the render.php files, but I feel like that’s a really inefficient way to do it, since the default config already works as it should.

    Is there perhaps a function or filter that could force the ACF renderTemplate over the core “render”, even when “render” is present in block.json?

    Simple file structure:
    src
    |--blocks
    | |-- carousel
    | | |-- block.json
    | | |-- render.php
    | |-- anotherBlock
    | | |-- block.json
    | | |-- render.php
    build
    |--blocks
    | |-- carousel
    | | |-- block.json
    | | |-- render.php
    | |-- anotherBlock
    | | |-- block.json
    | | |-- render.php</code?

    Registration:

    function my_register_acf_blocks() {
      register_block_type(dirname(__DIR__, 1) . '/build/blocks/carousel' );
      register_block_type(dirname(__DIR__, 1) . '/build/blocks/anotherBlock' );
    }
    add_action( 'init', 'my_register_acf_blocks' );

    Relevant lines of block.json:

    {
      "$schema": "https://schemas.wp.org/trunk/block.json",
      "apiVersion": 3,
      "name": "acf/carousel",
      "title": "Image or Video Carousel with Overlay",
      "render": "file:./render.php", //<-- webpack won't copy this to build without this, but ACF block breaks when present
      "script": "file:./index.js",
      "style":  ["splide", "file:./style-index.css"],
      "acf": {
        "mode": "edit",
        "renderTemplate": "render.php"
      }
    }

    webpack.config.js

    const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
    
    module.exports = {
    	...defaultConfig,
    	entry: {
    		...defaultConfig.entry(),
    		index: './src/index.js',
    		loginStyles: './src/sass/login-styles.scss',
    		splide: './src/js/splide.js'
    	},
    };

  • Solving

    Display ACF Block in a modal

    Hello,

    I’m working on a site where I want to open a modal with ajax to display some part of a post. In this part of the post there is an ACF block but, the CSS does not load 🙁
    I work with fancybox.
    Here is the code of the block template:
    acf_register_block(array(
    'name' => 'mentor-fa',
    'title' => __('Profil du mentor', 'frassu'),
    'category' => 'ad-blocks-2',
    'icon' => 'superhero-alt',
    'mode' => 'auto',
    'supports' => array(
    'align' => false,
    'mode' => false,
    ),
    'keywords' => array( 'mentor' ),
    'render_template' => FS_THEME_DIR . '/blocks/block-mentor/templates/block-mentor-template.php',
    'enqueue_assets' => function() {
    wp_enqueue_style( 'block-mentor', FS_THEME_URL . '/blocks/block-mentor/css/block-mentor.css' );
    },
    ));

    Is there something to add to the block? Or a callback in the facnybox init JS?
    Thanks !

  • Unread

    ACF date field won’t work in excluding posts from loop

    Hi guys,

    I’m currently building a website where I need to show coming events. I’m building the website on the Salient WordPress theme, and trying to customize it a bit with some code in a child theme.

    I’m changing the build in blog post loop of the theme, to show events instead. Within the code I made some few changes to sort them in the correct order (nog publish date, but event date) but I can’t seem to figure out how to exclude events that have their date passed.

    ` if( $orderby !== ‘view_count’ ) {

    $today = date(‘l j F’);
    $nectar_blog_arr = array(
    ‘post_type’ => ‘evenement’,
    ‘posts_per_page’ => $posts_per_page,
    ‘post_status’ => ‘publish’,
    ‘meta-key’ => ‘event_startdate’,
    ‘meta_query’ => array(
    ‘relation’ => ‘AND’,
    ‘date_clause’ => array(
    ‘key’ => ‘event_startdate’,
    ‘value’ => $today,
    ‘type’ => ‘DATE’,
    ‘compare’ => ‘>=’
    ),

    ),
    ‘orderby’ => array(
    ‘date_clause’ => ‘ASC’,
    ),
    ‘offset’ => $post_offset,
    ‘category_name’ => $category,
    ‘paged’ => $paged
    );`

    Any tips or tricks?

    Note: I tried many pieces of code that I found on this form, or other website, but some codes just breaks the loop, and won’t show the loop at all. Without any PHP errors as well. Weird right?

    Thanks in advance for all the help and suggestions!

  • Unread

    Query Filter on Relationship Field only on Frontend?

    I need to use the “acf/fields/relationship/query/” filter to limit the results returned. But here’s the problem, I only need to do this when the field is displayed in a frontend form. I’m not sure how I can limit this behavior as whether it runs on the frontend or admin it still runs through AJAX and tests positive for is_admin().

    Any suggestions are much appreciated.

Viewing 25 results - 76 through 100 (of 21,345 total)