Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

topic

  • Solving

    Repeater inside a group

    Hey all!

    I have the following ACF structure.
    A group with a repeater inside. The repeater also has two subfields, a text and time field

    Group
    > repeater
    >> Text – subfield
    >> Time – subfield

    I’m trying to add multiple rows of the repeater with an event schedule.

    
    $group_key = 'field_64e765bfc42ef';
    
        foreach ($event->lineup as $item) {
            $value = [];
            $value = array(
    
                'field_64e76f9210338' => array(
                   
                    array(
                        'field_64e770e717754' => $item->details,
                        'field_64e770f317755' => $item->time
                    ),
                ),
            );
    
            update_field($group_key, $value, $post_id);
        }
    

    The data in the API is structures as follows:

    
    "lineup": [
    {
    "details": "Doors open",
    "time": "9:00 PM"
    },
    {
    "details": "Last Entry",
    "time": "11:00 PM"
    },
    {
    "details": "Curfew",
    "time": "11:00 PM"
    }
    ],
    

    For each repeater row. I’m trying to output every “details” and “time” inside the “lineup” array. The output would be something like the image attached image.

    Is it possible to set up a repeater this way inside a group? I’ve tried a few different things but I only get one of the items in the line up array to output in the repeater. I’m not sure if this is possible, or if it’s something to do with the syntax etc. Hope this is making sense. Any help would be greatly appreciated.

    Thanks
    Simon

  • Solving

    Add ACF fields as Custom Order Line Item Meta

    Hello,

    How can I add a custom field data as Item meta when the order is saved? Is there anyone who has experience with that?

    https://drive.google.com/file/d/1Y_Q8kb1j3BZhLpbuH2OpqQyxL0bvF_MG/view?usp=sharing

    I tried the code below but it didn’t help:

    
    add_action( 'woocommerce_checkout_create_order_line_item', 'display_acf_on_orders_and_emails', 10, 4 );
    function display_acf_on_orders_and_emails( $item, $cart_item_key, $values, $order ) {
        $name = get_field('name', $order_id);
    
        if ( isset($values['name']) ) {
            $item->add_meta_data( 'Name', $values['name'] );
        }
    
    }
    

    Thank you in advance!

  • Solving

    Permalink and Title from two custom fields

    Hello, maybe it’s easy to solve with php or hidden somewhere in the settings.

    I have a post type mitarbeiter and two custom fields vorname and nachname. These fields are required.

    I would like the title to be generated from vorname und nachname in this post type and the url to be adjusted accordingly https://url/mitarbeiter/vorname-nachname.

    I can’t write php, I simply copy various php snippets into the plugin code snippet. Maybe you have a solution for me.

    thank you for your help

  • Unread

    Display file format and size

    We are using a custom field to enable zip and PDF downloads.

    How can we display the format and file size alongside the button? Please see this image for an example: https://www.dropbox.com/scl/fi/6wm97gl3qpdkvxhdlpbai/acf-file-info.png?rlkey=x77c95qoji7e8vqtntm6cmhsh&dl=0

    We are using the Cornerstone page builder, which has built in tools for ACF. At the moment I am display the full file path and name. See a screen grab here: https://www.dropbox.com/scl/fi/pa0xsp07tumkyou48wgn2/acf-file-format.png?rlkey=f5nvz05sjkanpli6bj9kcjzsn&dl=0

    I suspect that I will have to use a raw content container to add code into that instead.

    If anybody knows Cornerstone, these are the ACF options: https://www.dropbox.com/scl/fi/n1yu6uoa54dfg2nt14j1n/acf-cornertsone-options.png?rlkey=4z4h600pt0swwvmzdwr31s943&dl=0

    Apologies for all of the links, I hope I am being as clear as possible. Any suggestions would be great.

    Thanks,

    Spencer

  • Unread

    Export post CPT from another website

    Hi all!

    First forgive my baguette accent (yes I’m French)

    I’ve created two Post Types called “VN Hyundai” and “VN Volvo” edited with CPT and ACF Pro.
    The idea is to create post every time a new vehicle is produced by both brands (Hyundai and Volvo)
    I’ve set these CPT on this url https://dev.europauto-dunkerque.com/vn_volvo for CPT VN Volvo and https://dev.europauto-dunkerque.com/vn_hyundai/ for CPT VN Hyundai.

    It has been done first with ACFPRO and CPT UI.
    In a second time, I’ve exported CPT into ACFPro.

    I want to export that job into the prod website (CPT and its content)
    I’ve tried to import and export all with ACFPRO (doesn’t work)
    I’ve tried to import and export all with WordPress export options.

    It display the CPT and ACF Fields, well, but it doesn’t display all the post types like VN Volvo > XC90 or VN Hyundai>Kona…

    Can you tell me the proper way to import these content ?

    Thanks a lot

  • Unread

    “Adding custom javascript to fields,” a “show_field” question

    Hello ACF folks.

    I’m fairly new at, “Adding custom javascript to fields,” as detailed in the documentation here (https://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/) and could use some help understanding how to best use some of the code on that page.

    Specifically, I am trying to run some code when a specific field appears, conditionally. I am attempting to use “show_field” for this task. The idea is something like, “If field-A has value, check the value of field-A and add placeholder copy based on five different value ranges.”

    Question: The show_field functionality, on the page above, references the following code:

    acf.add_action('show_field', function( $field, context ){
        
        // context is a string of either 'tab' or 'conditional_logic'
        
        // do something to $field
        
    });

    How do I select a “$field” given the structure above? If the field isn’t available yet, how would I reference it with jQuery, or any other way? Everything I have tried has had errors.

    An example below:

    acf.add_action('show_field', function( jQuery('#relevancy1'), conditional_logic ) {...
    This version throws an “undefined” error, which makes sense since the element is not within the HTML, yet. How do I reference the element before it is ready to use?

    Hopefully this makes sense. Thanks for the help!

  • Unread

    excessive CPU/mySQL usage

    Hi all,

    My host (shared hosting) who is pretty reasonable has flagged my account for excessive usage on the shared server. One suggestion is that my custom blog module could be causing issues, because the wp-admin/admin-ajax.php file is flagged as constantly running.

    I modified the Blog.php in order to display custom fields contents… and we now have 19 custom fields
    here is the code I am using. It triggers in two places in the Blog.php file. Suggestions for improving the display are welcome – I hacked this together and suspect that it is inefficient.


    /* INSERT START position for Advanced Custom Fields Content -- aka vendor-links */
    $buttons = get_fields(); //get_field('repeater-field-name', 'options')
    if( $buttons ) {
    echo
    '<div class="button-strip et_pb_button_module_wrapper et_pb_button_3_tb_body_wrapper">';
    foreach( $buttons as $but_name => $but_value ) {
    if( !empty( $but_value ) ) {
    $but_label = get_field_object($but_name);
    $but_type = $but_label['type'];
    if( $but_type == 'url' )
    echo
    '', $but_label['label'] ,'';
    elseif( $but_type == 'text' && $but_name == 'special_button_form' ) {
    echo
    '<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
    <input type="hidden" name="cmd" value="_s-xclick">
    <input type="hidden" name="hosted_button_id" value="', $but_value ,'">';
    echo
    '<input type="image" src="https://www.readajs.com/wp-content/uploads/2023/01/checkout-paypal.png" border="0" width="150px" name="submit" alt="PayPal - The safer, easier way to pay online!">

    </form>';
    }
    elseif( $but_type == 'text' && $but_name == 'payhip_code' ) {
    echo
    'Order directly!';
    }
    elseif( $but_type == 'text' && $but_name == 'preorder_code' ) {
    echo
    'Pre-Order directly!';
    }
    }
    }
    echo
    '</div>';
    }
    /* INSERT FINISH position for Advanced Custom Fields Content -- aka vendor-links */

  • Unread

    ACF fields missing Gutenberg block

    Hello,

    I have ACF PRO 6.1.6 installed and have two environments one local and one staging which need to be the same. The fields created in the local environment are showing correctly however on the staging some are missing.
    Here are some screenshots
    options
    options
    options

    As you can see from the images the tab icon options -+ are missing as well as some other fields bellow the Data field. Also the fields do exist they just remain hidden. No extra CSS is added to hide those fields it’s simply from ACF itself.

    What i have tried to far is both environment are synced with the JSON files. I’ve also tried to remove the staging field group and import again from the local environment. That doesn’t work either. Cleared and disabled cache also doesn’t work. There are no conditions on those fields either.

    What steps should i take or check in order to get the fields appear again? Thanks.

  • Solving

    Field Group Presentation settings not working

    Hello, is there an issue with the following field group presentation settings?

    Style
    I don’t see a difference between using the Standard or Seamless setting.

    Position
    Regardless which setting I use, the group is always positioned below the content.

    Hide on screen
    I have selected several items on the screen that don’t need to be displayed, but they still are.

    Here are screenshots of my settings and the result. You see that the group is shown below the content, while it’s set to display after the title. You also see that I hide excerpt, format, author, tags, featured image, but the they are still shown.

    I checked the Chrome developer console and it shows one, I think unrelated, error for the field label:

    The label’s for attribute doesn’t match any element id. This might prevent the browser from correctly autofilling the form and accessibility tools from working correctly.
    To fix this issue, make sure the label’s for attribute references the correct id of a form field.

    <label for="acf-field_647c70126cffd">Menugang</label>

    Thanks

  • Unread

    ACF Pro vs CPT UI

    I don’t know if this is a bug or if I somehow just messed up the setup, but I tried making two similar post types in ACF Pro and in CPT UI, and I noticed that the post type created by ACF does not include the option to select a template and customize the slug.

    This is the ACF post type:
    ACF post type

    And this is the post type made with CPT UI:
    CPT UI post type

    The post types have different names, but their settings are pretty much the same. Can somebody tell me what exactly I have to enable in the ACF Pro post type for it to also have template selection and slug customization? Thank you!

  • Unread

    AJAX Search w/ Relationship Field

    I’ve stuck. How can I limit an AJAX search to only show posts in my relationship field? It’s currently coming back with results from all posts.

    Field
    Without Search
    With Search

    Query
    function get_answer_keys($search_term = null, $tests = null) {

    $tests = get_field('tests', false, false);

    $args = array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'orderby' => 'name',
    'posts_per_page' => -1,
    'post__in' => $tests
    );

    if (!empty($search_term)) {
    $args['s'] = $search_term;
    }

    return new WP_Query($args);
    }

    Block-Answer_keys.php
    <?php
    /**
    * Block Name: Related Section
    *
    * This is the template that displays a title + button + 4 blog posts.
    */

    $search_term = get_query_var('search_term');
    ?>

    <div class="filter">

    <div class="search-bar">
    <label for="answer_keys_search_term">Search</label>
    <input type="text" id="answer_keys_search_term" placeholder="Test Code Search" value="<?php echo $search_term ?>"/>
    </div>

    </div>

    <div class="ajax-container">
    <div class="grid--25">

    <?php
    $query = get_answer_keys($search_term, $tests);

    if ($query->have_posts()) :
    while ($query->have_posts()) : $query->the_post();
    get_template_part('template-parts/content', 'test');
    endwhile;
    wp_reset_postdata();

    else : ?>
    <div class="alert"><?php _e('Sorry, no posts matched your criteria.', 'nashville-mdha'); ?></div>
    <?php endif; ?>

    </div>
    </div>

    Ajax.js
    /** Answer Keys Search **/
    $('#answer_keys_search_term').blur(function(e) {
    getAnswerKeysSearchResults();
    });
    $('#answer_keys_search_term').keypress(function(e) {
    var keycode = (e.keyCode ? e.keyCode : e.which);
    if(keycode == '13') {
    getAnswerKeysSearchResults();
    }
    });

    function getAnswerKeysSearchResults() {

    var search_term = $('#answer_keys_search_term').val();

    $.ajax({
    url: wpAjax.ajaxUrl,
    data: { action: 'answer_keys_filter', search_term: search_term },
    type: 'post',
    beforeSend:function(xhr){
    setFilterElementsProp(true);
    },
    success: function (result) {
    setFilterElementsProp(false);
    if (result) {
    $('.ajax-container').html(result);
    }
    else {
    // No result
    $('.ajax-container').html('<div class="alert">Sorry, no results found.</div>');
    }
    },
    error: function(result) {
    setFilterElementsProp(false);
    console.warn(result);
    }
    });
    }

    Results.php
    add_action( 'wp_ajax_nopriv_answer_keys_filter', 'answer_keys_filter_ajax' );
    add_action( 'wp_ajax_answer_keys_filter', 'answer_keys_filter_ajax' );

    function answer_keys_filter_ajax() {

    $search_term = htmlspecialchars($_POST['search_term']);

    $query = get_answer_keys($search_term, $tests);

    if($query->have_posts()) {
    echo '<div class="grid--25">';
    while($query->have_posts()) { $query->the_post();
    get_template_part('template-parts/content', 'test');
    }
    echo '</div>';
    } else {
    ?> <div class="alert">Sorry, but nothing matched your search criteria. Please try again with some different keywords.</div> <?php
    }
    wp_reset_postdata();

    die();
    }

  • Solving

    ACF fields with Blocksy Theme

    Hi all, I’m using the ACF field to create and manage my custom post types

    So far i have created an ACF with multiple groups and multiple fields inside those groups.
    The ACF is displayed on a form on front-end and the posts are stored correctly under my custom Taxonomy.

    The issue I’m facing is while displaying the Single Post, where I cannot present any of the custom fields but only title/author/date.

    I found a YT video [07:55] that demonstrates how to add a ACF Field using the Theme Editor
    But for me the ACF Field is not present there! Is it because of my Theme – Blocksy, or could it be due to another reason?
    Blocksy Editor

  • Solving

    How can I display the values of a repeater-field from a post object?

    I wanted to display a repeater field from another post via Post object (setting: Post ID).

    var_dump shows all values – but how do I bring them in a for-each loop? The problem is that it is quite a nested array

    
    $materialien_repeater = get_field('materialien', $materialien_post);
    
    array(1) { ["materials"]=> array(4) { [0]=> array(1) { ["link-composition"]=> array(3) { ["img-url"]=> string(73) "https://cdn.pixabay.com/photo/2018/11/16/13/57/cosmos-3819483_960_720.jpg" ["link-url"]=> string(72) "https://pixabay.com/de/photos/kosmos-himmel-universum-raum-star-3819483/" ["copyright"]=> string(21) "@alinkon @pixabay.com" } } [1]=> array(1) { ["link-composition"]=> array(3) { ["img-url"]=> string(71) "https://cdn.pixabay.com/photo/2012/01/09/10/31/planet-11613_960_720.jpg" ["link-url"]=> string(71) "https://pixabay.com/de/photos/planet-mars-krater-victoria-krater-11613/" ["copyright"]=> string(20) "@WikiImages @pixabay" } } [2]=> array(1) { ["link-composition"]=> array(3) { ["img-url"]=> string(72) "https://cdn.pixabay.com/photo/2016/08/24/14/29/earth-1617121_960_720.jpg" ["link-url"]=> string(79) "https://pixabay.com/de/illustrations/erde-planet-welt-globus-weltkarte-1617121/" ["copyright"]=> string(20) "@PIRO4D @pixabay.com" } } [3]=> array(1) { ["link-composition"]=> array(3) { ["img-url"]=> string(109) "https://images.pexels.com/photos/757158/pexels-photo-757158.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1" ["link-url"]=> string(74) "https://www.pexels.com/de-de/foto/
    
  • Unread

    Simple Lightbox doesn’t work on my website

    Hello,

    I followed all the steps described in this post, I already disabled all plugins (except Simple Lightbox and ACF) but I can’t make it work.

    My gallery shows the images with the link to the WP file, which opens on click, not as a lightbox.

    If anyone can help, I greatly appreciate it. My code:

    function mostra_imagens() {
    	ob_start(); 
    	$fotos = get_field('galeria'); 
        if( $fotos ): ?>
    		<h3>Galeria de imagens</h3>
    		<div class="gallery">
    		<?php
    	   	foreach( $fotos as $foto ):
    			$content = '<div>';
    			$content .= '<a class="gallery_image" href="'. $foto['url'] .'">';
    			$content .= '<img src="'. $foto['sizes']['thumbnail'] .'" alt="'. $foto['alt'] .'" />';
    			$content .= '</a>';
    			$content .= '</div>';	
    			if ( function_exists('slb_activate') ) {
    				$content = slb_activate($content);
    			}
    			echo $content; 	
    	   	endforeach; ?>
    	    </div> <?php
    	endif; 
    	
    	$output = ob_get_clean();
    	return $output;	
    }

    In the inspector, I can see that the slb_activate() function has been executed:

    Object inspector

    Can anyone see what is wrong??

    Thanks in advance!

  • Unread

    The Movies Bio

    Life Style About – Positioned as a trendy, youthful and vibrant store, Lifestyle offers consumers an enjoyable shopping experience.
    Its Current Fashion – The current fashion trends see all-over brown blended with primary and secondary colours like kelly green, fire-engine red, and Pantone’s most intense hues.
    Entertainment Bee – Queen Bee Entertainment is a record label owned by American rapper and songwriter Lil’ Kim.
    The Shopping Pack – The Shopping Bags was a Canadian television series that aired on the W Network in Canada and on Fine Living in the United States.
    The Movies Bio – A biographical film or biopic is a film that dramatizes the life of a non-fictional or historically-based person or people

  • Unread

    Using ACF field in do_shortcode()

    I have tried the following:

    echo do_shortcode( '[video_lightbox_vimeo5 video_id="'.the_sub_field( 'expertise_video_video').'" width="1280" height="960" anchor="http://paraffin.foxrobinson.com/wp-content/uploads/2023/08/purple_square.jpg"]');

    As recommended here: https://wordpress.stackexchange.com/questions/275152/using-acf-field-in-do-shortcode

    But this doesn’t work. I get the message:

    “Error! You must specify a value for the Video ID, Width, Height and Anchor parameters to use this shortcode!”

    The field is a text field and outputs a Viemo ID. If I add the Vimeo ID in directly to the shortcode it works fine.

    I have also tried adding the field as a variable in this style:

    $idcode = get_field('id_code');
    echo do_shortcode('[shortcode id="'.$idcode.'"]');

    But get the same error message.

  • Helping

    Custom post type navigation ordered by ACF date field

    Hi there,

    I have a custom post type called ‘prime-ministers’

    On it’s archive page, it is ordered by an ACF date picker field called serving_period_1_start

    This works as expected

    However on each individual page, when I add Prev?next post navigation buttons, it always orders them by published date. I have tried many variations, and it’s always the same.

    This is my current code:

    	<div class="prime-ministers-post-nav full-width blue-bg">
    	<?php
    	 
    	 /* Infinite next and previous post looping */
    	 if( get_adjacent_post(false, '', true) ) { 
    		 previous_post_link('%link', '&larr; Previous Post');
    	 } else { 
    		 $arg_prev = array(
    			 
    			'post_type' => 'prime-ministers',
    			'meta_key' => 'serving_period_1_start',
    			'order' => 'DESC',
    			'orderby' => 'meta_value_num'
    	
    		  );
    		 $first = new WP_Query($arg_prev); 
    		 $first->the_post();
    		 echo '<a href="' . get_permalink() . '" class="prev-link"> &larr; Previous Post</a>';
    		 wp_reset_query();
    	 }; 
    	 
    	 if( get_adjacent_post(false, '', false) ) { 
    		 next_post_link('%link', 'Next Post &rarr;');
    	 } else { 
    		 $arg_next = array(
    			'post_type' => 'prime-ministers',
    			'meta_key' => 'serving_period_1_start',
    			'order' => 'ASC',
    			'orderby' => 'meta_value_num'
    		 );
    		 $last = new WP_Query($arg_next); 
    		 $last->the_post();
    		 echo '<a href="' . get_permalink() . '" class="next-link">Next Post &rarr;</a>';
    		 wp_reset_query();
    	 }; 
    	 
    	 ?>
    	</div>

    I am going a bit mad here, so any help would be greatly appreciated

  • Solving

    Can I safely delete the field references in post_meta?

    Hello,

    ACF is storing a “reference” for each field and value within post meta.
    → This means there are 2 entries for each meta value…

    Problem

    * ACF is a power tool, and when you start using it, you will always use it.
    * But it generates unnecessary, superfluous and redundant information

    We have a project with ~3 million entries in post meta, of this ~ 700,000 are these references…

    Question: Can I safely delete these values, if I don’t need them (render fields without ACF)?

    —————-

    What is the reference good for?

    → It is used to get the field type and render it “correctly”

    Proposal

    → have a filter to disable the storage (possibly don’t store it that way)
    → use some more smart way to find the field type
    → In know, same key could be different type
    → but there always should be a “unique” matching field configuration anyway, as it should be a problem having two fields on one view with the same key, but different types.

  • Solved

    Relationship Field Entries Not Showing

    Using current ACF.

    CPT 1: Reviews
    CPT 2: People

    In Reviews, created three Relationship fields:

    Cast
    Writers
    Directors

    Added those to a Field Group for Reviews.

    Entered all crew and cast entries in People CPT.

    Went to Reviews. Selected and entered the correct People posts into the three Reviews Relationship fields. Saved.

    Went back later. No visible entries in any of the three fields. Made entries again. Came back. They’re gone again.

    One symptom. Using the GeneratePress Query Loop and their specialized filter code, I am able to get they query in a Reviews page to reference the People CPT and the Cast CPT. It populates with all of the entries I entered the first time. Entries from all three relationship fields, not just the Cast CPT, populates from the query.

    Since the Relationship field entries disappearing from the Field post is all ACF, starting with you guys. There appears to be something in the database, but it’s not visible or editable.

    Hopefully it’s a basic configuration error on my part, but I’ve not strayed off the path from the UI.

  • Unread

    Custom Post Type with ACF-Fields

    Hello Community,

    I’ve been dealing with a problem for a few days that I can’t solve or where I need help.

    I created a Custom Post Type named Services using the Custom Post Type UI plugin. I then equipped this custom post type with ACF fields and then also output these values ​​on a page (single.service.php).

    Reading the values ​​on the page works!

    But now I would like to create an ACF Gutenberg block where I can ONLY display specific values ​​from the custom post type because the Gutenberg block must not be edited and should only serve as a view in the editor.

    Is something like this possible and if so how can I implement something like this?

    Thank you in forward,
    Martin

  • Solving

    Multisite Post Object

    I run a multisite (if I have my way it will stay ‘a’ but there you go) where it would be so useful to be able to offer the user a selection of Post Objects from another site.

    There used to be a plugin for this (since broken and unmaintained). I have tried to write a hook to do it but failed. (it seems switch_blog() does not work in a hook)

    So, feature request, Post Object field or Relationship field that can operate multisite please.

  • Solving

    Block preview is wrapped in “extra” div (same classes), affects appearance

    I would love to hear some thoughts on this one.

    I have multiple blocks on which I have a custom field for adding width classes to the block (I don’t like Gutenbergs approach, I need my own). The selected class is appended to the blocks other regular css classes on the object.

    On my ACF blocks I use get_block_wrapper_attributes() to get the classes and then add them to a wrapper div. Apparently these classes is also added to the preview wrapping div in admin which means I get a double effect of my css rules.

    It removes the attribute classes on the inner div whenever clicking on the block but it’s back again whenever I reload the page.

    Anyone got a clue on why this happens and how I can solve it (my soultion mught be bad, I’m of course open for other totally different solutions)? This worked fine, as far as I know, before the summer (just got back to work and discovered this after updating WP 6.2.2 -> 6.3. and ACF 6.1.7 -> 6.2.0).

    Preferably I would not want these classes on the preview wrapping div, however they should in that case not be removed on the inner div when clicking on the preview.

    Double width classes creates double distance from the edges

    Same classes added to both parent and child div in preview mode of ACF Gutenberg block

    My block code:

    
    <?php
    $custom_wrapper_classes = 'my-block';
    include_once (get_stylesheet_directory() . '/includes/blocks/block-functions.php');
    
    if (function_exists('hest_get_wrapper_attr')) :
    	$wrapper_attributes = hest_get_wrapper_attr($block, $custom_wrapper_classes);
    endif;
    
    $posts = get_field('my_relationship_field');
    
    if( $posts ): ?>
    
    	<div <?php echo wp_kses_data($wrapper_attributes); ?>>	
    
    		<div class="my-grid">
    			<?php
    			global $post;
    			foreach( $posts as $post): 
    				setup_postdata($post);?>
    
    				 <!-- Code for outputting data -->
    			<?php
    			endforeach; ?>
    		</div><!-- .my-grid -->
    
    	</div><!-- .wrapper -->
    
    	<?php
    	wp_reset_postdata();
    
    endif; ?>
    

    hest_get_wrapper_attr() looks like this:

    
    <?php
    /*
     * Converts Gutenberg saved data attributes (input field by IPM plugin) to 
     * a string to echo on the wrapping div
     */
    function conv_data_attributes($data_attributes) {
    
        $data_attr = '';
        // Regular expression pattern to match the value inside the brackets
        $pattern = '/\[(.*?)\]/';
    
        // Perform the regular expression match
        if (preg_match_all($pattern, $data_attributes, $matches)) {
            // Extract the matched values
            $values = $matches[1];
            // Remove the commas from each extracted value
            $data_attr = array_map(function ($value) {
                return str_replace(',', '', $value);
            }, $values);
            // Convert the array into a space-separated string
            $data_attr = implode(' ', $data_attr);
        }
    
        return $data_attr;
    }
    
    /*
     * Converts Gutenberg saved gap value to CSS
     * 
     */
    function conv_blockgap_value($gap) {
        
        $pattern = "/var:([^|]+)\|([^|]+)\|([^|]+)/";
    
        $result = preg_replace_callback($pattern, function ($matches) {
            $lastValue = $matches[3];
            $updatedLastValue = preg_replace("/(\d+)([a-zA-Z]?)/", "$1-$2", $lastValue);
            return "var(--wp--{$matches[1]}--{$matches[2]}--{$updatedLastValue})";
        }, $gap);
    
        $gap = "gap: " . $result . ";";
        
        return $gap;
    }
    
    /*
     * Main function to prepare all wrapper classes, styles and attributes
     * 
     */
    function hest_get_wrapper_attr($block, $custom_wrapper_classes) {
        
        $wrapper_attributes = '';
        $alignment_classes = '';
        $style = '';
    
        // Support custom anchor values.
        $anchor = '';
        if ( ! empty( $block['anchor'] ) ) {
            $anchor = 'id="' . esc_attr( $block['anchor'] ) . '" ';
            $wrapper_attributes .= $anchor;
        }
    
        // Create class attribute allowing for custom "className" and "align" values.
        if ( ! empty( $block['align'] ) ) {
            $alignment_classes .= ' align' . $block['align'];
        }
    
        if ($block['supports']['alignContent'] == 'matrix') {
            // If matrix
            // Replace spaces: center left becomes center-left
            $alignment_classes .= ' has-custom-content-position is-position-' . str_replace(" ", "-", $block['alignContent']);
        } else {
            if ( ! empty( $block['alignContent'] ) ) {
                // If not matrix, get the alignContent
                // either top, center, or bottom
                $alignment_classes .= ' is-vertically-aligned-' . $block['alignContent'];
            }
        }
    
        // Block text alignment
        if( !empty($block['alignText']) ) {
            $alignment_classes .= ' has-text-align-' . $block['alignText'];
        }
    
        // Check if the block has fullHeight turned on
        if( !empty($block['fullHeight']) ) {
            $style .= 'min-height: 100vh;';
        }
        
        // Check if we got custom data attributes to add to our main div
        $data_attr = $block['dataAttributes'] ?? null;
        if ($data_attr && function_exists('conv_data_attributes') ) :
            $data_attr = conv_data_attributes($data_attr);
        endif;
    
        // Add blockGap value to wrapper attributes
        $gap = $block['style']['spacing']['blockGap'] ?? null;
        if ($gap && function_exists('conv_blockgap_value') ) :
            $gap = conv_blockgap_value($gap);
        endif;
    
        $style .= $gap;
    
        $wrapper_attributes .= get_block_wrapper_attributes(
            [
                'class' => $custom_wrapper_classes . $alignment_classes,
                'style' => $style,
            ]
        );
    
        $wrapper_attributes = $wrapper_attributes . ' ' . $data_attr;
    
        return $wrapper_attributes;
    }
    
  • Solving

    Customize main query to sort by ACF number field

    Hi – I would like to customize the main query in all locations to order by an ACF number field instead of by date. I don’t want any other modifications, just this. Am I on the right track with this?

    
    function tas_album_query( $query ) {
    	
    	if ( ! is_admin() && $query->is_main_query() ) {
    		// Not a query for an admin page.
    		// It's the main query for a front end page of your site.
    
    		if ( is_category() ) {
    			// It's the main query for a category archive.
    
    // Let's change display order for the query for category archives.
    		$query->set( 'orderby', 'meta_value_num' );
    		$query->set( 'meta_key', 'tas_album_admin_acf_tas_album_order' );
    		$query->set( 'order', 'ASC' );
    	}
    }
    }
    add_action( 'pre_get_posts', 'tas_album_query' );
  • Solved

    using get_field_object but only if there are values

    I’m trying to use a (long list) of fields that i want to display their value and their label.

    If i wasn’t displaying their label I would do this:

    $field1 = get_field('myfirstfield');
    $field2 = get_field('mynextfield');
    $field3 = get_field('mylastfield');
    
    if ($field1) echo '<p>1st: '.$field1.'</p>';
    if ($field2) echo '<p>2nd: '.$field2.'</p>';
    if ($field3) echo '<p>3rd: '.$field3.'</p>';

    This works fine and only shows the data if the field has a value. However Now I’m trying to use a field label to so I tried this code:

    $field1 = get_field_object('myfirstfield');
    $field2 = get_field_object('mynextfield');
    $field3 = get_field_object('mylastfield');
    
    if ($field1) echo '<p>$field1['lablel']: '.$field1['value'].'</p>';
    if ($field2) echo '<p>$field2['lablel']: '.$field2['value'].'</p>';
    if ($field3) echo '<p>$field3['lablel']: '.$field3['value'].'</p>';

    However it outputs each paragraph regardless of data in the field. I know this is likely a very simple question but what am I doing wrong?
    I thought of doing this:

    $field1 = get_field('myfirstfield');
    if ($field1) {
         $field1 = get_field_object('myfirstfield');
         echo '<p>$field1['lablel']: '.$field1['value'].'</p>';
    }

    But this seems overly complex for some reason and would be hard to repeat for the 15 fields.
    I looked at get_fields() so I could simplify this as well, but don’t want to show ALL fields from the page. it did seem to show that i could pull name from just fields instead of objects.
    Is there a better way to make a for loop? (that would be just a sidenote to the question and icing on my cake)

  • Helping

    Help Request: My repeater is not showing up on the new page I created

    I am using WordPress for my job and I am quite unfamiliar with it as I have always used other building sites. I have created a repeater for a new page on the website and the repeater is not showing up on the site.

    The below photo is the repeater I added and it is what won’t show up. Is there anything I need to do in the backend settings to get it to show whenever I preview the page?.

Viewing 25 results - 476 through 500 (of 21,345 total)