Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • This reply has been marked as private.
  • Thanks for the snippet.

    I made two changes. One was to add the ‘function’, and the second was to change it so that no Admin fields are required vs making all Front End fields required.

    add_filter('acf/prepare_field', 'not_required_in_admin');
            function not_required_in_admin($field) {
                if (is_admin()) {
                    $field['required'] = false;
                    }
            return $field;
    }
  • use https://www.advancedcustomfields.com/resources/acf-prepare_field/ see options there

    
    add_filter('acf/prepare_field', 'required_on_front');
    required_on_front($field) {
      if (!is_admin()) {
        $field['required'] = true,
      }
      return $field;
    }
    
    
  • I am looking for this functionality as well. Has anyone come up with a good solution since?

    The form changes regularly and has conditional questions that are required if they are shown – so I’d like to avoid custom scripts to do it. My client also doesn’t have the budget to pay me to do that.

    Would there be a way to disable the required fields on the backend?

  • Yep, I didn’t mean to take away from the original intent of the feature request. The two big things are definitely not having to access the fields via array, and then the styling. For now I’m stuck using the ACF Columns plugin, which is a great “hack”, but something native to ACF would make so much more sense.

  • Please note that this feature request is now 6 years old. Item 2 has been thoroughly solved by the introduction of clone fields some years ago.

    I would still, to this day, love to see an option to remove the group header for groups that really, really don’t need it. But over time this has wilted into “minor annoyance.” Right now I have the honor of actually working with Elliot on another completely different issue and for this reason I am diving really deep into the codebase, getting very familiar with the code. Maybe I will find a solution and propose it myself. Maybe it will even be possible using a plugin. Let’s see.

  • Well, I may have just solved the issue for myself after reviewing what I pasted above. In acf_register_block_type I was using a script name (apm-quote-slider) that I was using for a different script. After updating that to a unique name for this script the problem seems to be resolved.

  • I’m having this same issue. Using slick slider instead of owl. When I add images to either a repeater or gallery the callback does not fire. Here’s my JS. Some of the slider logic is imported, but that doesn’t seem to be the issue. It won’t even console log the message and date I’ve got setup.

    Now, if I save the page and reload the editor then things seem to work fine. The callback fires and the slider properly initializes. It’s only when a new block is added and edited that this problem appears.

    
    import { default as sliders } from "../../../assets/src/js/modules/_sliders.js";
    
    (function ($) {
    
    	/**
    	 * initializeBlock
    	 *
    	 * Adds custom JavaScript to the block HTML.
    	 *
    	 * @date    15/4/19
    	 * @since   1.0.0
    	 *
    	 * @param   object $block The block jQuery element.
    	 * @param   object attributes The block attributes (only available when editing).
    	 * @return  void
    	 */
    	var initializeBlock = function( $block ) {
    
    		var d = new Date();
    		var n = d.toLocaleTimeString();
    
    		console.log( 'setup sliders on back end ' + n );
    
    		var slider = $block[0].querySelector(".js-image-slider");
    
    		if (slider) {
    			sliders.setupImageSlider(slider);
    		}
    
    	}
    
    	// Initialize each block on page load (front end).
    	$(document).ready(function () {
    
    		const imageSliders = document.querySelectorAll(".js-image-slider");
    
    		if (imageSliders) {
    			imageSliders.forEach(element => {
    				sliders.setupImageSlider(element);
    			});
    		}
    
    	});
    
    	// Initialize dynamic block preview (editor).
    	if (window.acf) {
    		window.acf.addAction('render_block_preview/type=image-slider', initializeBlock);
    	}
    
    })(jQuery);
    
    
           acf_register_block_type( array(
            'name'            => 'image-slider',
            'title'           => __( 'Image slider', 'apm-theme' ),
            'description'     => __( 'Displays an image slider', 'apm-theme' ),
            'render_template' => 'blocks/acf-image-slider/acf-image-slider.php',
            'category'        => self::get_block_category('slug'),
            'mode'            => 'preview',
            'enqueue_assets' => function() {
              APM_Theme::enqueue_vendor_resources( 'slick' );
              wp_enqueue_script( 'apm-quote-slider', get_template_directory_uri() . '/blocks/acf-image-slider/assets/acf-image-slider.min.js', array('jquery', 'slick'), '', true );
            },
           ) );
    
  • Yes you can, it requires adding rewrite rules add_rewrite_rule() and rewrite tags add_rewrite_tag(). This does not cover this specific topic but might help you https://1fix.io/blog/2016/02/05/parent-from-another-cpt/

  • I don’t think that you can modify this.

    Not sure if it can be done, but I would look into removing the .sortable from the specific element on one of the acf JS action hooks. https://www.google.com/search?q=jquery+remove+.sortable

  • Well, I realized that much, I was looking for specifics – something like a list of the styles and scripts used.

    I understand for example, that ACF itself uses the select2 plugin in the admin in several cases, but I don’t get why this is loaded through the acf_form_head function in the frontend – in an ideal workflow, the plugin would somehow manage to see which field types are used and load the necessary scripts. On top of that having additional options on ‘heavy’ components – like the Repeater – to toggle on/off features not required, eg the sortable function or remove the tooltips.

    ..since this is not the case, I am willing to try by the good’ol’ trial-and-error method to see what works and what breaks in my frontend.

    Any pointers to specific script/style handles will be appreciated!

  • Any individual script or style sheet can be removed using https://developer.wordpress.org/reference/functions/wp_dequeue_script/ and https://developer.wordpress.org/reference/functions/wp_dequeue_style/. The trick is finding the right handle and the right time to remove them. For acf I would try the acf/admin_enqueue_scripts hook with a high priority. However, you may see unintended side effects since a lot of ACF depends on these 3rd party scripts and styles.

  • You can if you want to use get_post_meta() instead of ACF functions. However, this will return unformatted values and you’ll need to format them yourself if needed. The meta keys for repeaters look like "{$repeater_name}_{$row_index}_{$sub_field_name}" and you would use something like get_post_meta($post_id, $field_name, true) https://developer.wordpress.org/reference/functions/get_post_meta/

  • <?php
    
    $args = array( 'orderby' => 'count', 'order' => 'DESC', 'number'=>2);
    $tags = get_tags($args);
    if($tags){
    	echo '<div id="dle-content">';
    	foreach($tags as $tag) {
    		$link = get_term_link($tag);
    		echo '<a href="'.$link.'">  <article class="movie-item movie-item1"> <div class="movie-cols movie-cols1 clearfix"> ';
    		$size = "thumbnail";
    		$image = get_field('tag_img', 'tag_'.$tag->term_id);    
    		echo ' <div class="movie-img movie-img1 img-box pseudo-link"> <div class="movie-img-inner"> <i class="fa fa-folder-open" data-link=""></i> </div> <img src="' . $image . '" />'; 
    		echo ' </div> <div class="movie-text movie-text1"> <div class="movie-title cardname">' . $tag->name . ' </div> </div> ';
    		echo ' </div> </article></a>';
    	} 
    	echo '</div>';
    }    
    
    ?>

    thumbnail is not showing

  • I need to copy/mirror the value of a site option field city_name to a field on each post npe_city_name so that another plugin, Network Posts Extended, can use it. [NPE’s job is to pull a list of posts from my network’s subsites and display them on the main site. NPE can display ACF fields at the post level, but it can’t do the equivalent of get_field( 'nn_city_name', 'options' ).]

    The following does most of what I want:

    function my_acf_load_value( $value, $post_id, $field ) {
      if ( is_string( $value ) && $value != get_field( 'nn_city_name', 'options' ) ) {
        $value = get_field( 'nn_city_name', 'options' );
      }
      return $value;
    }
    // Apply to field with key "field_5f610abd75a19" AKA 'npe_nn_city_name'
    add_filter( 'acf/load_value/key=field_5f610abd75a19', 'my_acf_load_value', 10, 3 );

    There’s one shortcoming with the above: it requires that all the existing posts will need to be re-saved on the subsites before they will get the new npe_city_name value.

    Is there a better way?

    The difference between acf/load_value and acf/update_value is lost on me here. They seem to be interchangeable.

  • Off course (as this is just a simple test, I put my css inline):

    <div class="testwidget" style="height: 400px; width: 100%; background-color: blue; background-position: center; background-size: cover; background-image:url('<?php echo get_field( 'widgetbackgroundimage', 'widget_' . $widget_id ); ?>');">
    </div>
  • You have to show us your changed code if you want help, we aren’t psychic. But anyway, here is the modified code from your first example, assuming your field is now a taxonomy field with return value “Term Object”:

    
    <div class="audio-tags">
    <?php
    	$tags = get_field("etiquetas");
    	foreach($tags as $tag){
    ?>
    	<a href="<?php echo(esc_url(get_term_link($tag))); ?>"><?php echo($tag->name); ?></a>
    <?php
    	}
    ?>
    </div>
    

    And the adjusted CSS for this would be:

    
    .audio-tags {overflow: hidden;}
    .audio-tags a {
    	position: relative;
    	display: inline-block;
    	margin-right: .5em;
    }
    .audio-tags a:before {
    	content: '';
    	width: .25em;
    	height: .25em;
    	position: absolute;
    	background-color: blue;
    	border-radius: 100%;
    	left: -.5em;
    	top: 50%;
    	transform: translateY(-50%);
    }
    
  • You’re topics are being marked as spam. This can happen when you too quickly edit a post and submit. After you’re post is marked as spam until someone fixes it all of your posts will be marked as spam.

  • 
    add_filter( 'parse_query', 'ba_admin_posts_filter' );
    add_action( 'restrict_manage_posts', 'ba_admin_posts_filter_restrict_manage_posts' );
    
    function ba_admin_posts_filter( $query )
    {
        global $pagenow;
        if ( is_admin() && $pagenow=='edit.php' && isset($_GET['ADMIN_FILTER_FIELD_NAME']) && $_GET['ADMIN_FILTER_FIELD_NAME'] != '') {
            $query->query_vars['meta_key'] = $_GET['ADMIN_FILTER_FIELD_NAME'];
        if (isset($_GET['ADMIN_FILTER_FIELD_VALUE']) && $_GET['ADMIN_FILTER_FIELD_VALUE'] != '')
            $query->query_vars['meta_value'] = $_GET['ADMIN_FILTER_FIELD_VALUE'];
        }
    }
    
    function ba_admin_posts_filter_restrict_manage_posts()
    {
    $fields = array(
      'field_1',
      'field_2',
      'field_3',
      'field_4',
      'etc...'
    );
    ?>
    <select name="ADMIN_FILTER_FIELD_NAME">
    <option value=""><?php _e('Filter By Custom Fields', 'baapf'); ?></option>
    <?php
        $current = isset($_GET['ADMIN_FILTER_FIELD_NAME'])? $_GET['ADMIN_FILTER_FIELD_NAME']:'';
        $current_v = isset($_GET['ADMIN_FILTER_FIELD_VALUE'])? $_GET['ADMIN_FILTER_FIELD_VALUE']:'';
        foreach ($fields as $field) {
    	printf('<option value="%s"%s>%s</option>', $field, $field == $current? ' selected="selected"':'', $field);
    }
    ?>
    </select> <?php _e('Value:', 'baapf'); ?><input type="TEXT" name="ADMIN_FILTER_FIELD_VALUE" value="<?php echo $current_v; ?>" />
    <?php
    }
    
  • Hi John

    thanks for the reply.

    so my code bellow how it will be after adding the codes you have in your reply?

    could you please reply with the full code as per you early reply.

    
    
    add_filter( 'parse_query', 'ba_admin_posts_filter' );
    add_action( 'restrict_manage_posts', 'ba_admin_posts_filter_restrict_manage_posts' );
    
    function ba_admin_posts_filter( $query )
    {
        global $pagenow;
        if ( is_admin() && $pagenow=='edit.php' && isset($_GET['ADMIN_FILTER_FIELD_NAME']) && $_GET['ADMIN_FILTER_FIELD_NAME'] != '') {
            $query->query_vars['meta_key'] = $_GET['ADMIN_FILTER_FIELD_NAME'];
        if (isset($_GET['ADMIN_FILTER_FIELD_VALUE']) && $_GET['ADMIN_FILTER_FIELD_VALUE'] != '')
            $query->query_vars['meta_value'] = $_GET['ADMIN_FILTER_FIELD_VALUE'];
        }
    }
    
    function ba_admin_posts_filter_restrict_manage_posts()
    {
        global $wpdb;
        $sql = 'SELECT DISTINCT meta_key FROM '.$wpdb->postmeta.' ORDER BY 1';
        $fields = $wpdb->get_results($sql, ARRAY_N);
    ?>
    <select name="ADMIN_FILTER_FIELD_NAME">
    <option value=""><?php _e('Filter By Custom Fields', 'baapf'); ?></option>
    <?php
        $current = isset($_GET['ADMIN_FILTER_FIELD_NAME'])? $_GET['ADMIN_FILTER_FIELD_NAME']:'';
        $current_v = isset($_GET['ADMIN_FILTER_FIELD_VALUE'])? $_GET['ADMIN_FILTER_FIELD_VALUE']:'';
        foreach ($fields as $field) {
            if (substr($field[0],0,1) != "_"){
            printf
                (
                    '<option value="%s"%s>%s</option>',
                    $field[0],
                    $field[0] == $current? ' selected="selected"':'',
                    $field[0]
                );
            }
        }
    ?>
    </select> <?php _e('Value:', 'baapf'); ?><input type="TEXT" name="ADMIN_FILTER_FIELD_VALUE" value="<?php echo $current_v; ?>" />
    <?php
    }
    
  • So, I’ve run into similar issues with other field types in the past. For example, you can’t just set the value of an image field with the id and have the image appear. In that case I needed to do an AJAX request to get the image ID and the image URL for the correct size image after reading the image size attribute from the image field. Once I had this information I needed to set the image, set the url and also needed to add/remove classes in elements of the image field. Basically what I needed to do was to dig through the ACF code and figure out how ACF did it and then duplicate what it was doing.

    In this case your dealing with a post object field which uses select2 and this is likely complicating matters. Without spending a great amount of time digging through ACF JS code and actually trying to build this myself I wouldn’t be able to tell you exactly what you need to do.

    Going to be honest, in these cases I try to stick with basic field types that are easily manipulated, like the select field that you say works. It is usually not as pretty but it gets the job done.

  • Tipically. Snippet to prevent duplicate slugs makes it.

    function bhrs_save_post_callback( $post_ID, $post, $update ) {
        if (in_array($postarr['post_type'], array('post', 'page', 'chronik', 'mitglied', 'galerie', 'vorstand', 'event')) &&
    !in_array($data['post_status'], array('publish', 'draft', 'pending', 'auto-draft', 'future', 'private', 'trash')))
    
            return;
        // unhook this function to prevent infinite looping
        remove_action( 'save_post', 'bhrs_save_post_callback', 10, 3 );
        // update the post slug (WP handles unique post slug)
        wp_update_post( array(
            'ID' => $post_ID,
            'post_name' => ''
        ));
        // re-hook this function
        add_action( 'save_post', 'bhrs_save_post_callback', 10, 3 );
    }
    add_action( 'save_post', 'bhrs_save_post_callback', 10, 3 );

    This one leave ACF slugs alone:

    // Force slug auto generate
    function myplugin_update_slug( $data, $postarr ) {
    if (in_array($postarr['post_type'], array('post', 'page', 'chronik', 'mitglied', 'galerie', 'vorstand', 'event')) &&
    !in_array($data['post_status'], array('publish', 'draft', 'pending', 'auto-draft', 'future', 'private', 'trash'))) {
    $data['post_name'] = sanitize_title( $data['post_title'] );
    }
    return $data;
    }
    add_filter( 'wp_insert_post_data', 'myplugin_update_slug', 9, 2 );
  • Instead of doing the query to get a list of all avialble fields, construct an array with the field that you want to search.

    
    $fields = array(
      'field_1',
      'field_2',
      'field_3',
      'field_4',
      'etc...'
    );
    

    then alter the code used to display the field to use this new array

    
    foreach ($fields as $field) {
    	printf('<option value="%s"%s>%s</option>', $field, $field == $current? ' selected="selected"':'', $field);
    }
    
  • The best place to get questions like this answered would likely be either from the theme author or more likely from Visual Composer on how to show/not show html based on the value of a custom field.

  • For those who want my final code

    http://somesite.com/page/?agent=1

    
    $post_id = false;
    if ( isset( $_GET[ 'agent' ] ) ) {
      $post_id = intval( $_GET[ 'agent' ] );
    
      $value = get_field( "phone", $post_id );
    
      if ( $value ) {
        echo $value;
      } else {
        echo 'empty';
      }
    }
    }
Viewing 25 results - 6,426 through 6,450 (of 21,337 total)