Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • Hi, my date picker field is still not getting the translated value after using the snippet above. I have read this could be a bug after WordPress 5.3?

    I am using WordPress 5.5 + ACF PRO 5.9.0 + Polylang Pro 2.8.1 and the following code:

    wp_date("F Y", strtotime(get_sub_field('date')));

    wp_date is the alternative to date_i18n after WordPress 5.3. date_i18n is giving me the month text only in English too.

  • For several of my plugins and themes I have code that basically does the same thing that ACF is currently doing. I do have one theme where field groups that are synced from the parent theme are then saved in the child theme so that they can be modified on a per site basis. This theme is currently not active on any sites but is is a model that I have been know to use.

    I don’t have an answer for this at the moment

    You might want to send the question to support and see if they can help you with a solution or perhaps add something to ACF in an update that will allow what you are looking for. https://www.advancedcustomfields.com/contact/

  • I’m not sure that I can. The issue is that you have multiplier forms. The fields in each form need to be unique to each post and you need to test for this uniqueness to update the post that the form belongs to.

  • After sifting through pages, here’s the solution to the empty rendered grey box. Credit goes to paulmiller3000.

    All you have to do is move this portion of the helper code to the bottom of the page.

    
    <script type="text/javascript">
    (function( $ ) {
    
    /**
     * initMap
     *
     * Renders a Google Map onto the selected jQuery element
     *
     * @date    22/10/19
     * @since   5.8.6
     *
     * @param   jQuery $el The jQuery element.
     * @return  object The map instance.
     */
    function initMap( $el ) {
    
        // Find marker elements within map.
        var $markers = $el.find('.marker');
    
        // Create gerenic map.
        var mapArgs = {
            zoom        : $el.data('zoom') || 16,
            mapTypeId   : google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map( $el[0], mapArgs );
    
        // Add markers.
        map.markers = [];
        $markers.each(function(){
            initMarker( $(this), map );
        });
    
        // Center map based on markers.
        centerMap( map );
    
        // Return map instance.
        return map;
    }
    
    /**
     * initMarker
     *
     * Creates a marker for the given jQuery element and map.
     *
     * @date    22/10/19
     * @since   5.8.6
     *
     * @param   jQuery $el The jQuery element.
     * @param   object The map instance.
     * @return  object The marker instance.
     */
    function initMarker( $marker, map ) {
    
        // Get position from marker.
        var lat = $marker.data('lat');
        var lng = $marker.data('lng');
        var latLng = {
            lat: parseFloat( lat ),
            lng: parseFloat( lng )
        };
    
        // Create marker instance.
        var marker = new google.maps.Marker({
            position : latLng,
            map: map
        });
    
        // Append to reference for later use.
        map.markers.push( marker );
    
        // If marker contains HTML, add it to an infoWindow.
        if( $marker.html() ){
    
            // Create info window.
            var infowindow = new google.maps.InfoWindow({
                content: $marker.html()
            });
    
            // Show info window when marker is clicked.
            google.maps.event.addListener(marker, 'click', function() {
                infowindow.open( map, marker );
            });
        }
    }
    
    /**
     * centerMap
     *
     * Centers the map showing all markers in view.
     *
     * @date    22/10/19
     * @since   5.8.6
     *
     * @param   object The map instance.
     * @return  void
     */
    function centerMap( map ) {
    
        // Create map boundaries from all map markers.
        var bounds = new google.maps.LatLngBounds();
        map.markers.forEach(function( marker ){
            bounds.extend({
                lat: marker.position.lat(),
                lng: marker.position.lng()
            });
        });
    
        // Case: Single marker.
        if( map.markers.length == 1 ){
            map.setCenter( bounds.getCenter() );
    
        // Case: Multiple markers.
        } else{
            map.fitBounds( bounds );
        }
    }
    
    // Render maps on page load.
    $(document).ready(function(){
        $('.acf-map').each(function(){
            var map = initMap( $(this) );
        });
    });
    
    })(jQuery);
    </script>
    

    More specifically, put it after the:

    
    $location = get_field('map');
    if( $location ): ?>
    	<div class="acf-map" data-zoom="15">
    		<div class="marker" data-lat="<?php echo esc_attr($location['lat']); ?>" data-lng="<?php echo esc_attr($location['lng']); ?>"></div>
    	</div>
    <?php endif; ?>
    

    Hope this saves people time looking to resolve this.

  • Was there ever a solve to this? I’m able to remove drafts/pending items from the left hand side of a relationship field via this code:

    `
    // Only published posts
    function filter_acf_relationship($args, $field, $post_id)
    {
    $args[‘post_status’] = ‘publish’;
    return $args;
    }

    add_filter(‘acf/fields/relationship/query’, ‘filter_acf_relationship’, 10, 3);
    `

    However, I have an upload form for a user on the front-end, and when they submit something it goes straight to draft/pending and they automatically show up in the relationship field as (draft), which is undesirable. How could I remove the draft/pending items from the right-side of the relationship field?

  • Hi! thanks so much for your interesting in helping me!
    I’m having trouble understanding the location rules, which ones would refer to the WP dashboard? There’s nothing in that list that would give me the hint of it.

    I’ve only set “current user” equals “viewing backend”. (I’ve translated it from spanish since that’s my language, sorry).

    I guess obviously that’s not enough, what would I need to put there so that the field is only visibile in the dashboard/User/profile page?

  • As this is quite an advanced issue it might be a good idea to create ticket on github acf repo. There, Elliot answers all tickets

  • You need to somehow target the field to the post ID of the post being edited and then only update that post.

    maybe something like this (only a quick example)

    
    if (!empty($_POST['star_ratingg'][$post->ID])) {
      $star_ratingg = $_POST['star_ratingg'][$post->ID];
      $set_comments = $_POST['set_comments'][$post->ID];
      // remainder of your update code here
    }
    
    
    <input type="text" name="star_ratingg [<?php echo $post->ID]">
    <input type="text" name="set_comments[<?php echo $post->ID]">
    
  • I can’t give you any advice on using a different table, but since you mention that you don’t know how WP works I will give you some insight into it.

    When you are in “The Loop”

    
    while (have_posts()) {
      the_post();
    }
    

    part of what WP does automatically is that it gets all of the post meta values for the current post in a single query, or it should, and stores all of the values in the meta cache for the post. Queries for individual post meta values should not be made in this case.

    When you are getting values for other posts when not in a loop and WP is not automatically setting up the post and getting the meta values then it is possible that WP will do a query for each meta value. However, there is a solution for this.

    
    get_post_meta($post_id);
    

    When you call get_post_meta() with a post ID and no meta key specified then WP gets all of the post meta values for the post in a single query and stores the values in the cache so that later it will not, or should not, perform individual queries for each meta value.

    If you still want to go with custom tables then you might want to look at this https://www.awesomeacf.com/storing-acf-data-custom-database-tables/

  • I would not bother with a field for the Instagram URL. I would just have a “intagram user name” field and then if it’s filled in then output the url in code, something like this:

    
    if (get_field('intagram_user_name')) {
      ?><a href="https://instagram.com/<?php 
            the_field('intagram_user_name'); ?>" target="_blank>Instagram</a><?php 
    }
    

    Storing the actual URL to instagram for every user seems like a waste of DB space.

  • I’ve managed to fix it. I included JS in the backend as well and listed ‘acf-blocks’ as a dependency in the enqueue_block_editor_assets hook. Once that one was deleted it was working fine again.

  • Hi, I created a “country” ACF and I want to show it only on the dashboard/user details. I´ve set “User Form is equal to Add/Edit” but it is not showing there.

    Otherwise the country field appears everywhere!! Like in the Post editing page, lol.

    Thanks for reading,
    B

  • Ok I ended up with a solution, here is the code, don’t hesitate to comment!

    						<?php $spes = get_field( 'rel_spes', false, false ); if ( $spes ) : ?>
    
    	<?php 
    		$types = get_terms( array(
    		    'taxonomy' => 'job-type',
    		    'hide_empty' => true,
    		    'object_ids' => $spes 
    			)
    		);
    		
    		foreach( $types as $type ) : 
    		
    		$args = array(
    		    'post_type'         => 'job',
    		    'posts_per_page'    => -1,
    		    'post__in'          => $spes,
    		    'orderby'           => 'post__in',
    			'tax_query' => array(
    				array(
    					'taxonomy' => 'job-type',
    					'terms' => $type->slug,
    					'field' => 'slug',
    				),
    			),							    
    		);
    		$jobs = new WP_Query($args); 
    	?>
    		<p class="widget-title job-types"><?php echo $type->name; ?></p>
    		
    		<ul class="sidebar-menu">
    			<?php foreach( $jobs->posts as $post ) : setup_postdata( $post ); ?>
    			<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    			<?php endforeach; wp_reset_postdata(); ?>
    		</ul>
    		
    	<?php endforeach; ?>
    
    <?php endif; ?>	
    	
    
  • I’m also seeing this issue, albeit with many less admin-ajax.php requests. It feels like loading in all of the blocks at once is not the ideal solution, when it could be done with an intersection observer, or at least some kind of buffer system (or… ideally a toggle to only load the block when you actually click on it’s container)

  • I think I have solved it.

    From what I understand for a taxonomy the value mst be the ID rather than the name or slug or whatever, so since I need to use the name I need to convert that to the ID. I found that I could do this using get_term_by();

    This is the portion of code I needed to change:

       // Get term by name 'windows' in custom taxonomy 'product-types'.
        $termId = get_term_by( 'name', 'windows', 'product-types' );
        
        // compose our query arguements
        $args = array(
            'post_type'     => 'colourswatch',
            'meta_query'    => array(
                array(
                    'key'       => 'colour_swatch_$_availability', // repeater_$_subfield
                    'value'     => $termId->term_id, // translate the term name into its ID
                    'compare'   => 'LIKE'
                )
            )
        );
  • For me, the problem was that the JSON file that I was trying to import had a comma where there wasn’t suppose to be. Specifically it was on the last line of the location array. Here’s an example, notice here that there is a comma at the end of the “value” line:

    
    "location": [
       [
          {
             "param": "post_template",
             "operator": "==",
             "value": "components\/logo-heading-cta.php",
          }
       ]
    ],
    

    When I removed that comma, like this:

    
    "location": [
       [
          {
             "param": "post_template",
             "operator": "==",
             "value": "components\/logo-heading-cta.php"
          }
       ]
    ],
    

    Then the JSON file imported without any problem. I noticed this because my text editor showed that the comma there was a syntax error. It seems JSON is specific about not having a comma after the last item in an array.

    Maybe this will be the solution for anyone else trying to find an answer to this problem.

  • Thanks John. This worked like a charm. Having a couple issues on my end with the saved values being removed on subsequent post updates but 99% sure that’s on my end.

  • Hey Team – I was hoping to get a more current response to the personal license on a WP multisite install question. I found one other forum support entry about this and the answer seemed to suggest that ACF wasn’t designed for multisite. This made me curious about the feasibility of my use case scenario. That other forum entry is here: https://support.advancedcustomfields.com/forums/topic/multisite-license-with-domain-mapping/

    I’m using a multisite with the subfolder setup, as in: mydomain.com/subsiteA, mydomain.com/subsiteB, etc.

    I’m wanting to install and network activate a personal license supported ACF Pro within the network admin. My goal is to make and use independent options pages within the individual subsites. Will a single license personal ACF Pro be a workable solution in this scenario? Or does this require individually licensed Pro plugins for each subsite?

    Please advise, thanks! -Paul

  • @vipstephan This has been of help, thank you. With a little bit of experimentation I’ve been able to successfuly do a query based on a sub field that is a basic text field value but all attempts at doing the same for a custom taxonomy – which I was hoping to do – have so far failed.

    In my updated code below the taxonomy is ‘availability’ and the taxonomy name I’m aiming to filter to in this case is ‘windows’.

    In functions:

    function my_posts_where( $where ) {
    	$where = str_replace("meta_key = 'colour_swatch_$", "meta_key LIKE 'colour_swatch_%", $where);
    	return $where;
    }
    add_filter('posts_where', 'my_posts_where');

    and on my template:

    <?php
    
        $args = array(
            'post_type' => 'colourswatch',
            'meta_query' => array(
                array(
                    'key' => 'colour_swatch_$_availability',
                    'value' => 'windows',
                    'compare' => 'LIKE'
                )
            )
        );
        $query = new WP_Query( $args );
        
        if ( $query->have_posts() ) : 
        ?>
        <div class="container container--narrow swatches">
            <?php while ( $query->have_posts() ) : $query->the_post(); ?>
            <div class="swatches__material">
    
                <h3 class="swatches__title"><?php the_title(); ?></h3>
    
                <?php if( have_rows( 'colour_swatch' ) ): ?>
                <ul class="swatches__colours">
                    <?php while ( have_rows( 'colour_swatch' ) ) : the_row(); ?>
                    <li class="swatches__swatch">
                        <div class="swatches__colour" style="background:<?php the_sub_field( 'colour' ); ?>"></div>
                        <h4 class="swatches__name"><?php the_sub_field( 'colour_name' ); ?></h4>
                    </li>
                    <?php endwhile; ?>
                </ul>
    
                <?php endif; ?>
            </div>
            <?php endwhile; wp_reset_postdata(); ?>
        </div>
        <?php endif; ?>

    What am I missing?

  • Answering my own question… found a snippet online that resolves the issue – credit to whoever provided it!

    
    add_action( 'wp_print_scripts', 'pp_deregister_javascript', 99 );
    
    function pp_deregister_javascript() {
    	if(!is_admin())
    	{
    		 wp_dequeue_script('wp-color-picker');
    		 wp_deregister_script( 'jquery-ui-datepicker' );
    		 wp_deregister_script( 'wp-color-picker-js-extra' );
    		 wp_deregister_script( 'wp-color-picker' );
    
    	}
    
    }
  • Did you get an answer to your question?

    I have a similar construction (pun intended). I develop sites for builders and have a FLOORPLANS Custom Field Group with fields liked Bedrooms QTY, Bathrooms QTY, Square Feet, Price, etc. I also have a HOMES field group with Floorplans populated with the namefrom the other field group via Post Options but I would also like to bring over Bedrooms, Baths, etc. from FLOORPLANS. Essentially a clone of the values from FLOORPLANS and then let the user customize the values if necessary.

  • @jenssogaard Well done! Thank you!

    Following your lead I added recursion to easily access nested blocks.

    https://gitlab.com/micqey/acf-block-helper/-/blob/master/acf-block-helper.php

  • Hi JOhn,

    Yes, i’m using YT video’s.

    Yes, I have jQuery running (link to jQuery library in header.php).

    I also tried the javascript in my site-main.js file without any luck.

    Probably the script is the issue, nut I do not have any knowledge of javascript myself.

    regards,

    Roland

  • Are these youtube videos you are trying to defer? It may be that it does not work with some video types.

    Are you loading jQuery on the page in question? My JS depends on jQuery. I usually put the script in a “site.js” file that is enqueued for the site and set the depends argument array('jquery)` If you are not using jQuery then the script would need to be rewritten to use vanilla JS.

Viewing 25 results - 6,501 through 6,525 (of 21,339 total)