Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • Added some error logging, and all the cpt’s are being found

    function populate_users_field_with_speakers($field) {
        // Switch to Site 1
        $site_1_id = 1; // Replace with your Site 1 ID
        switch_to_blog($site_1_id);
    
        // Fetch all speakers
        $args = array(
            'post_type' => 'speakers',
            'post_status' => 'publish',
            'posts_per_page' => -1
        );
    
        $speakers_query = new WP_Query($args);
    
        // Reset choices
        $field['choices'] = array();
    
        // Loop through speakers and add to field choices
        if ($speakers_query->have_posts()) {
            while ($speakers_query->have_posts()) {
                error_log('posts found');
    
                $speakers_query->the_post();
                $field['choices'][get_the_ID()] = get_the_title();
                error_log( $field['choices'][get_the_ID()]);
    
            }
           // error_log(var_dump($field['choices']));
            wp_reset_postdata();
        }else{
            error_log('no posts found');
        }
    
        // Restore to current blog (Site 2)
        restore_current_blog();
    
        return $field;
    }
    add_filter('acf/load_field/name=speaker_name', 'populate_users_field_with_speakers');
  • found a workaround in case someone needs similar code… i show/hide field groups based on another acf field value i use in an option page:

    add_filter('acf/get_field_group', 'my_change_field_group_priceinfo');
    function my_change_field_group_priceinfo($group) {
    	if($group['title'] != 'Preisinfo') return $group;
    	if(!get_field("priceinfo","options)){
    		require_once ABSPATH . 'wp-admin/includes/template.php';
    		\remove_meta_box('acf-'.$group["key"], 'post', $group["position"]);
    	}
    	
    	return $group;
    }
  • I solved the problem through a series of PHP functions. Now the plugin no longer generates two post meta for each field, but only one post meta for all fields.

    Now one last problem remains for me to solve. When I enter, save or reload the page dedicated to the field groups in question, the page takes several times to load. About 10 to 20 seconds. What is this due to since it no longer creates the meta posts when they are created?

  • I would like to +1 @kevinspanish comment. Having a required field that is hidden by conditional logic seems to create that bug. As mentioned the error only occurs when the edit page is reloaded.

  • Not sure if this is already fixed in an upcoming release, but I’d like to add my two cents.

    Best way that I have found to replicate this is to make a repeater-field with two required text fields and a true/false which is used for conditional logic.
    Set one textfield to show when the true/false is unchecked and hide the other. viceversa for when the true/false is checked.

    IE;
    Textfield A*: show if value is equal to unchecked.
    Textfield B*: show if value is equal to checked.

    If you then reload the edit page it wil invalidate the block and prevent the entire page from being updated. When you nibble on the true/false checkbox (or kick any field in the repeater) it will update and presumably see the conditional logic and validate the field again, allowing you to update the page.
    Although, it doesn’t seem to be limited to just repeaters, as similar logic in the block itself has problems too.

    This is in combination with ACF’s Gutenberg block functionality by the way.

  • <p>FAJ Technical Services LLC is your premier choice for quality AC repair in Dubai. With 14 years of experience, we are the most trusted air conditioning service company in Dubai, UAE. FAJ provides AC repair and maintenance services to all areas of Dubai. Our skilled technicians specialize in repairing all AC types, brands, and models, ensuring your home or business stays cool and comfortable.</p>

  • I forgot to mention that the update_field() is taking so long because the programs repeater field has about 60 sub-fields, including another repeater “locations” inside of it.

    Maybe updating 300 (schools) * 60 (total fields) will just take this long? Was hoping for something sub 10 seconds, since 18000 updates seems like it shouldn’t take 60 seconds

    I’ve also tried several “wp_importing” tricks, none of which have decreased the time to import

    ex: set_time_limit(0);
    ignore_user_abort();
    wp_defer_term_counting( true );
    wp_defer_comment_counting( true );
    $wpdb->query(‘SET autocommit = 0;’);
    if (!defined(‘WP_IMPORTING’)) {
    define(‘WP_IMPORTING’, true);
    }
    $wpdb->query(‘ALTER TABLE wp_postmeta DISABLE KEYS;’);

    with appropriate cleanup after

  • Same issue is occurring with block fields. On initial edit screen load the block shows as Validation Failed. Changing any value of any field in the block will clear the error.

    The setup for the block in question is using 3 fields where 2 of them are conditionally displayed based on the third field.

    Structure:

    Content type (select field): Image or Video

    Image File (image field, conditional based on Content type being Image)
    Video URL (text field, conditional based on Content type being Video)

  • I am surprised this isn’t a plugin yet. ACF fields are the biggest gap to using the Query Loop more often.

  • Yes, I noticed this too @shauny and thanks @hube2 for the info. Adding what I’ve found to this to hopefully help. First up, this is a known issue apparently. So, if anyone wants to follow it or contribute to fixing it, please check it out.

    Until it is fixed, if you are simply removing the query string as John mentioned, your browser like will still cache the CSS file (mine does, so I have to resort to CTRL+F5 hard refresh on every change). You really do need the automatic cache busting that WP already does for JavaScript assets added in block.json. Until then, the only other thing you can do is add and adjust the “version” setting in your block.json file each time you change something. That would mean doing something like this:

    
     "version": "0.1.3" 
    
  • This works however, not if you don’t want margin/padding on for other blocks. The above method will turn it on for all blocks. You’ll have to assign your acf block within the theme.json and give it custom elements like so…

    "settings": {
    	
    		"blocks": {
    			
    			"acf/acf-block-name": {
    				"spacing": {
    					"margin": true
    					
    				}
    			},
    		
    		
    			
    		}
    	},

    This will bring up the detail just for your acf block.

    However, I am not having the problem that the margin setting I’ve chosen is just adding the number to the inline style and no measurement i/e 20px it just adding margin-top: 20;

  • Thanks @peterseb for this solution. Worked for me, on a Post Object field. In my case I needed users (admins actually) to be able to search for a post by its ID. Here’s my code for that:

    function cf_post_object_query( $args ) {
        // Set a query variable to identify the post object query
        $args['is_acf_query'] = true;
        // return
        return $args;
    }
    // filter for a specific field
    add_filter('acf/fields/post_object/query', 'cf_post_object_query');
    
    function cf_search_where( $where, $wp_query ) {
        global $pagenow, $wpdb;
        $is_acf = isset( $wp_query->query['is_acf_query'] ) ? $wp_query->query['is_acf_query'] : false;
        if ( is_search() || $is_acf ) {
            $where = preg_replace(
                "/\(\s*".$wpdb->posts.".post_title\s+LIKE\s*(\'[^\']+\')\s*\)/",
                //"(".$wpdb->posts.".post_title LIKE $1) OR (".$wpdb->postmeta.".meta_value LIKE $1)", $where );
                "(".$wpdb->posts.".post_title LIKE $1) OR (".$wpdb->posts.".ID LIKE $1)", $where );
        }
        return $where;
    }
    add_filter( 'posts_where', 'cf_search_where', 10, 2 );
  • Looks like now it is possible with the latest ACF (v6.3).
    I got the ide from stackoverflow, where @cybmeta suggested to “set the slug argument for your custom post type to ‘/’ when registering the post type”. I did the same with ACF and now it seems like it is working well.

  • You need to use a more complex meta query that checks if the selected month lies within the range of the start and end dates. Here’s an updated version of your query that should achieve this:

    $sel_month = '05';
    $sel_year = '2024'; // Adjust as needed or get this dynamically
    $sel_month_start = $sel_year . $sel_month . '01';
    $sel_month_end = date("Ymt", strtotime($sel_month_start));
    
    $meta_query = array(
        'relation' => 'AND',
        array(
            'key'     => 'start_date',
            'value'   => $sel_month_end,
            'compare' => '<=',
            'type'    => 'DATE'
        ),
        array(
            'key'     => 'end_date',
            'value'   => $sel_month_start,
            'compare' => '>=',
            'type'    => 'DATE'
        ),
    );
    
    $query = new WP_Query(array(
        'post_type' => 'your_post_type',
        'meta_query' => $meta_query
    ));

    This code constructs a date range for the selected month and uses it to make sure the post’s start date is before the end of the selected month and the post’s end date is after the start of the selected month. And plz remember to adjust 'your_post_type' to your actual post type.

  • function acf_header_script() {
      $queried_object = get_queried_object();
      if (is_a($queried_object, 'WP_Post')) {
        $schema = get_field('schema_code', $queried_object->ID);
        echo '<script type=application/ld+json>' . $schema_code . '</script>';
      }
    }
    add_action ( 'wp_head', 'acf_header_script' );

    When I want to use it on a Page (e.g. on “Home”), how I must fix this code?
    (It doesn´t work on Homepage if I use this code + ACF Field “schema_code”)

  • Plz know that using multiple CSS files for each block can lead to excessive HTTP requests and inefficient caching, especially if your blocks are modular and numerous. I would suggest you to consolidate your CSS into one larger file to reduce the number of requests and improve caching efficiency.

    It simplifies maintenance and optimizes performance and ensures that necessary styles are readily available across your site without compromising speed. And tools like Litespeed for CSS generation can further streamline the process and enhance performance.

  • I made some updates to the javascript so that it shows a small loading icon inside the preview button until the ajax request is finished. It makes it feel a bit less hacky I guess 😉 For some reason it’s not letting me post it here, so you can get it here: https://pastebin.com/wGNttfSV

  • @creativelogic This is the answer I received from the ACF support.

    Hey there,

    Unfortunately, this is expected behaviour. You’ll need to manually rename your local JSON files to match the new file structure if you want to apply it to an already build website.

    Thanks,
    Liam

    So I think we can wait for the answer from @lgladdy in an upcoming release to fix this issue. Actually, I didn’t use the hook acf/json/save_file_name and still using the old json file names because it didn’t work properly.

  • Hey adeiza. Are you the same person that initially replied to my question (username: abbas)?

    I guess they took my email too seriously over at WP Engine and thought that every post except mine was spam and any other user other than me was a scammer.

    I explicitly told them that there is a person that legitimately tries to help me while a random spammer posts a book promotion service.

    And they banned your account too? That’s a bit careless from the forum admins.

    Anyway, I will get in touch with you to discuss further about this.

  • I can’t try to another WordPress installation.
    I wish that ACF Team have an answer for this question/issue.

    Thank you very much.

  • Hi,

    My previous account was trashed alonside the spammer’s account.

    You see my previous comments were deleted too. and your last response is in private.

    Well that’s for their community rules.

    We may talk further via abqariyuh [@] gmail.com

  • today i had some capacities to give it a try. because there is a viewScript node, i discovered there is also a viewStyle node. And both are working similar. They both load the assets only if the block i actually used. But viewStyle loads the file as inline-css in the <body>. So this seems finally solved for me.
    my old code:

    "style": ["file:./assets/tabgroup.css","tabgroup"],
    "script": ["file:./assets/tabgroup.js","tabgroup"],

    recent working code:

    "viewStyle": ["file:./assets/tabgroup.css","tabgroup"],
    "viewScript": ["file:./assets/tabgroup.js","tabgroup"],
  • I just did some experiments and I struggle a bit with how the workflow should be.

    Here’s how I did it to create block in my custom post type template.

    register_block_type(... path to folder containing block.json ...)

    – My block.json looks like this

    {
    	"name": "my-theme/template-quote",
    	"title": "Template Quote",
    	"category": "theme",
    	"icon": "format-quote",
    	"style": "wp-block-quote",
    	"acf": {
    		"usePostMeta": true,
    		"renderTemplate": "./template-quote.php"
    	}
    }

    – Adding a field group for this block.

    – When using Editor for block theme creating a custom template, the above block was not pickable until I removed the row "usePostMeta": true, so I added the block before adding the row again.

    – This was not enough to get the block editable when editing my custom post, because it was “outside” of my “Content” block, but it shows up in when using the Template Preview functionality.

    – I tried to add my custom post type to the ACF field group location rule, so it shows up for block or post type. I also changed presentation positiịn to “Side”, to get my ACF fields to show up in my custom post type sidebar in the block editor.

    Final thoughts / wishes / bugs(?)

    – To be able to add my block to the custom post type single template in the theme editor when usePostMeta: true, is important for my current dev workflow for building a block theme.

    – Editing my custom fields in the post editor sidebar will not update the block preview. Currently I need to reload the editor after update to see my changes in preview mode.

    – In Template Preview mode, I’m missing to be able to select my block to edit it – this would be awesome.

  • Hey everyone,

    Not sure why ACF hasn’t put more priority on this annoying issue, since it’s been going on for years. That said, I’ve created a workaround. It’s super hacky and not ideal, but it works.

    Basically what this does is intercept the Preview button’s click event, sends the form data to an Ajax function that creates an autosave, and once that’s done it triggers a click on the Preview button. After the first click it removes itself, so it’ll only do this once.

    Here’s the javascript that needs to be included in the admin area:

    jQuery( ( $ ) => {
    
    	let previewBtn = $( '#preview-action .preview' );
    
    	if ( previewBtn.length ) {
    
    		let previewIntercept = $( '<span id="preview-action--trigger" style="position: absolute; left: -1px; right: -1px; top: -1px; bottom: -1px;"></span>' );
    
    		previewBtn.css( 'position', 'relative' ).append( previewIntercept );
    		previewIntercept.click( ( e ) => {
    
    			const formData = new FormData( $( '#post' )[0] );
    
    			formData.set( 'action', 'create-preview-autosave' );
    
    			$.ajax( {
    				url: ajaxurl,
    				method: 'post',
    				data: formData,
    				cache: false,
    				contentType: false,
    				processData: false,
    				success: () => {
    					previewIntercept.remove();
    					previewBtn.trigger( 'click' );
    				},
    			} );
    
    			e.preventDefault();
    			e.stopPropagation();
    
    		} );
    
    	}
    
    } );

    And here’s the WP Ajax function that should go in functions.php or wherever you want:

    add_action( 'wp_ajax_create-preview-autosave', function() {
    	wp_create_post_autosave( $_POST );
    	header( 'HTTP/1.1 200 OK' );
    	wp_die();
    } );
  • Can i find a update of this code ? I have try, But not working.

    I use now this code:

    function dd_query_by_event_date( $query ) {
    $query->set( ‘orderby’, ‘meta_value’ );
    $query->set( ‘meta_key’, ‘start_date’ );
    $query->set( ‘meta_query’, array(
    array(
    ‘key’ => ‘start_date’,
    ‘value’ => date( ‘Y-m-d’ ),
    ‘compare’ => ‘>=’,
    ‘type’ => ‘DATETIME’,
    ),
    ) );
    }
    add_action( ‘elementor/query/dd_event_date’, ‘dd_query_by_event_date’ );

    But with this code you have the problem as described above, the problem that it no longer displays everything from the start date

Viewing 25 results - 2,776 through 2,800 (of 21,334 total)