Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • Hi,

    I just migrated a Website from Drupal to WordPress using the FG Drupal to WP plugin and after some difficulties (process kept stopping and had to be resumed constantly), I succeeded. The problem is that yes, the plugin requires the use of Toolset Types, which I don’t want to use, I prefer ACF like most people around here.

    So it works, but now I need to turn Toolset fields into ACF fields, and if I understand that I need to recreate all the fields in ACF, i don’t see how I can transfer the content of the Toolset fields to the new ACF ones.

    In his message, @pixeline doesn’t say anything about that part, only to modify the template, but it looks like there’s a missing step between 3 and 4: move the Toolset data to ACF fields.

    If @pixeline or @muzKore (or somebody else) can give me a hand here, I’d appreciate ☺️

    Ch.

  • OK, I’m going to answer my own question. It took a little time, but you can do it. For now, I’ve edited the core files, but will make my own ACF field to not interfere with the base datetimepicker.

    Two things to know:
    1. The datetimepicker is an extension of the jQuery UI date picker. It has a known bug that will NOT allow the time to be set in inline mode. However, I have a fix for that.
    2. To activate inline mode, you need to target a <div> or <span> as the target for the datetimepicker instead of the <input> tag.

    So, step one is to update the render_field method in the acf_field_date_and_time_picker.php file and class.

    Just to keep to the style of the existing code, I inserted a new DIV using the acf methods here:

    
    		$text_input = array(
    			'class' 				=> 'input',
    			'value'					=> $display_value,
    		);
    
    		$inline_calendar = array(
    			'class'					=> 'calendar-inline input'
    		);
    		
    		
    		// html
    		?>
    		<div <?php acf_esc_attr_e( $div ); ?>>
    			<?php acf_hidden_input( $hidden_input ); ?>
    			<?php // acf_text_input( $text_input ); ?>
    			<div <?php acf_esc_attr_e( $inline_calendar ); ?>></div>
    		</div>
    		<?php
    		
    	}
    

    This will insert the div below the text input, and comment out the text input.

    Next, update the acf-input.js file to edit the javascript of the picker.

    Note that the datetimepicker is an extension of the date picker. So, around line 5811 there will be a definition for the date_picker and it will declare the $inputText.

    
    		$inputText: function(){
    			return this.$('.calendar-inline');
    			// return this.$('input[type="text"]');
    		},
    

    This should now return your .calendar-inline class instead of the <input> tag.

    Lastly, a bit further down, in the date_time_picker section (not date_picker section) there is a declaration to add.newDateTimePicker on line 6031. We need to update that to update the calendar with the current time.

    
    	// add
    	acf.newDateTimePicker = function( $input, args ){
    		
    		// bail ealry if no datepicker library
    		if( typeof $.timepicker === 'undefined' ) {
    			return false;
    		}
    		
    		// defaults
    		args = args || {};
    		
    		// NEW - Remember date/time
    		$date = args.altField[0].value;
    
    		// initialize (This wipes the datetime in inline mode)
    		$picker = $input.datetimepicker( args );
    
    		// update to current datetime with the value 2 lines above.
    		$picker.datetimepicker('setDate', (new Date($date)) );
    		
    		// wrap the datepicker (only if it hasn't already been wrapped)
    		if( $('body > #ui-datepicker-div').exists() ) {
    			$('body > #ui-datepicker-div').wrap('<div class="acf-ui-datepicker" />');
    		}
    	};
    

    We effectively store the datetime before we initialise the datetimepicker and then update it once it’s created.

    Now you should have an embedded calendar.

    Couple of gotchas:
    1. Remember to hard-reload and clear cache to reload the new JS.
    2. The acf-input.min.js gets loaded by default, you can test the acf-input.js by updating the /includes/assets.php file and the enqueue_script location OR just define the constant SCRIPT_DEBUG to use the non-minified version.

  • That is correct. I just got it though. So I changed the link to a text field.

    then added this to the child theme functions file:

    add_shortcode( 'itinerary_link', 'shortcode_itinerary_link');
    function shortcode_itinerary_link(){
    
    	$link_variable = get_field('the_itinerary_link');
    	$link = '<a href='.$link_variable.' class="button--gold3" target="_blank" rel="noopener noreferrer">Itinerary</a>';
    	return $link;
    }

    and added the shortcode in place of the button in the code module:

    <div id="request_form">  
    <a href="#iframe-popup" class="button--gold3 open-iframe-popup">Register</a>
    [iframe_popup]
      
    [itinerary_link]
    </div>
  • I’ve tried multiple browsers and it still throws the same error.

    In the browser console it’s thowring the following error (screenshot):

    Uncaught TypeError: can't access property "BlockControls", C is undefined acf-pro-blocks.min.js:1:9076

  • This is happening to me as well. I have seen on many forums that to count the total rows within a repeater you use count(); But when I place it in gettype() it returns boolean.

    Code
    $count = count(get_sub_field('dates_locations'));
    print_r($count);

    The error output:
    Warning: count(): Parameter must be an array or an object that implements Countable in...

    Not being able to grab the total row count has been causing unnecessary problems. Any advice would be highly appreciated.

    Places that refer to getting the total number of rows from a repeater using count():

  • Any ideas? Yes.

    If you are not using a child theme then create on and change to it.

    Create an override template for buddypress where you want to add the gallery to be edited https://wproot.dev/blog/override-buddypress-template-files/

    Use acf_form(), supply the correct post ID for the user "user_{$user_id}" and set 'form' => false and other settings as needed to show the groups/fields that you want to add https://www.advancedcustomfields.com/resources/acf_form/ In the override template place the call to acf_form() inside the existing buddypress form.

  • Yes, this is possible, but complicated, and I don’t have any specific code to share.

    For the first bit, populating fields when a term is selected, you need to write JavaScript that makes an ajax request to get and populate the fields when the tax field changes. https://www.advancedcustomfields.com/resources/javascript-api/. There are some examples of doing similar things here (some work, some do not) https://github.com/Hube2/acf-dynamic-ajax-select-example.

    You’ll also need to create an acf/prepare_field filter that will load these fields’ values with current values from the term when a post is edited to reflect any changes made from another post.

    For the second part you need to create an acf/save_post filter that takes the submitted values and updated the term.

  • @byates2019

    Whenever you get the error page instead the error message for validation the cause of this is either a JavaScript error or a PHP error during the AJAX request. If it works without the stripe script but fails with it then the likely cause of this is an error caused by that script and you need to figure out what that error is and correct it.


    @carlxxon

    As far as implementaion goes, I can’t really help you here, but maybe @byates2019 will reply.

  • For Select or Multiselect dropdown use the below code to query only parents.

    function hide_child_taxonomies( $args, $field ) {
        if( 'YOUR_FIELD_NAME' === $field['_name'] ) {
            $args['parent'] = 0;
        }
        return $args;
    }
    
    add_filter('acf/fields/taxonomy/query', 'hide_child_taxonomies', 10, 3);
  • For Select or Multiselect dropdown use the below code to query only parents.

    function hide_child_taxonomies( $args, $field ) {
        if( 'YOUR_FIELD_NAME' === $field['_name'] ) {
            $args['parent'] = 0;
        }
        return $args;
    }
    
    add_filter('acf/fields/taxonomy/query', 'hide_child_taxonomies', 10, 3);
  • Hi, thanks for the reply. I should have explained that this is below the content on a single-cpt.php page.

    What I think I will do is run the above query and create an array of ordered post IDs. Then I’ll find the current post’s ID and choose the IDs directly before and after my one.

  • If you are talking about the WP search form, No, you cannot search posts by term name. The built in WP search will not even search posts by term even without ACF. https://wordpress.stackexchange.com/questions/2623/include-custom-taxonomy-term-in-search

  • The default order of terms in WP is alphabetically by term name and ACF does not apply any arguments to change this except to show hierarchical taxonomies group by parent term.

    If you are seeing a different order I would look for a filter or some other cause of this issue.

    The only filter in ACF that can be used to change this is acf/fields/taxonomy/query

  • No, but you can specify both the key (value) and the label

    
    red : 1
    green : 0
    blue : 1
    

    Not sure if that helps, but I don’t quite understand what you’re trying to do.

  • I am assuming from your explanation that the post object field allows multiple selections

    
    $args = array(
    	'numberposts'	=> -1,
    	'post_type'		=> 'tv',
    	'meta_key'		=> 'instruments',
    	'meta_value'	=>  '"'.$post->ID.'"'
    	'meta_compare' => 'LIKE'
    );
    
  • So you have several problems with this query.

    The first being that you cannot do
    {POST AUTHOR} OR {META QUERY} The query being run will always be {POST AUTHOR} AND {META QUERY} and it does not matter that you’ve added 'relation' => 'OR', to the meta query, this only effects the meta query itself. See this information on searching by content or custom fields, the concept here would be similar https://adambalee.com/search-wordpress-by-custom-fields-without-a-plugin/

    What you need to do is, in your filter above you need to add additional add_filter(..... statements to perform the filtering that will alter the where part of the query in order to do{POST AUTHOR} OR {META QUERY}.

    When you get past that then the next issue it your use of “EXISTS” This just checks that the field exists in the DB and does not compare any value so any value specified is ignored. You are using a field that is stored as a serialized array of user IDs.

    You are also using the field key and not the field name, this will always return false because this meta_key value will never exist, you need to use the field name.

    What you need here is

    
    'meta_query' => array(
      array(
        'key' => 'field-name',
        'value' => '"'.$author_id.'"',
        'compare' => 'LIKE'
      )
    )
    
  • It’s been a little while, but I wanted to build onto what ChrisAtMogul started here because this worked wonders for me, but I had to do some tweaking to get it to work the way I needed it.

    Chris’s code is good for working with one multiselect field, because it allows you to whittle your results in the same field down. However, what I wanted to do was to select a parent taxonomy term in a select, and then have another ACF field directly after that only listed the child terms. That way, they could be pulled from ACF as distinct entities if need be.

    So, this requires two fields, both assigned the Taxonomy type. And please note that this is only a singluar level parent/child relationship. Any further, and you’d need to add more to the JS and to the PHP to make this cascade into grandchildren, etc.

    jQuery/Javascript

    (function($){
    
    	$(document).ready( function() {
    	
    		acf.add_filter('select2_ajax_data', function( data, args, $input, field, instance ){
    
    			var parent_field_key = 'field_5f4fcb8f3a1a2'; // Parent Field
    			var target_field_key = 'field_5f4fd4201446c'; // Child Field
    
    			if( data.field_key == target_field_key ){
    
    				var field_selector = 'select[name="acf[' + parent_field_key + ']"]'; //the select field holding the values already chosen
    
    				if( $(field_selector).val() != '' && $(field_selector).val() != null ){
    
    					parent_id = $(field_selector).val();
    
    				} else{
    
    					parent_id = 0; //nothing chosen yet, offer only top-level terms
    
    				}
    
    				data.parent = parent_id;
    
    			}
    
    		  	return data;
    
    		});
    
    	});
    
    })(jQuery);

    Functions file

    function custom_acf_taxonomy_hierarchy( $args, $field, $post_id ){
    
    	$parent_id = false;
    
    	if ( $field['key'] == 'field_5f4fcb8f3a1a2' ) { // Parent
    		$parent_id = 0;
    	} else if ( $field['key'] == 'field_5f4fd4201446c' && !empty( $_POST['parent'] ) ) { // Child
        	$parent_id = (int)$_POST['parent'];
        }
        if ( $parent_id !== false ) {
        	$args['parent'] = $parent_id;
        }
    
        return $args;
    }
    add_filter('acf/fields/taxonomy/query/key=field_5f4fcb8f3a1a2', 'custom_acf_taxonomy_hierarchy',10,3); // Parent
    add_filter('acf/fields/taxonomy/query/key=field_5f4fd4201446c', 'custom_acf_taxonomy_hierarchy',10,3); // Child

    I hope this manages to help someone like ChrisAtMogul’s code helped me. Thanks again!

  • I have an example of doing this with a relationship field, unfortunately, it has not been updated to work with the new ACF JS API and will not work in the current version of ACF.

    What you have to do is to add an action on the relationship/post object field that triggers an AJAX request to get and populate the values in the other fields. As I said, this old example will not work, but it covers the basics https://github.com/Hube2/acf-dynamic-ajax-select-example/tree/master/dynamic-fields-on-relationship

    This example has been updated to work with the current version of ACF and shows the differences from the old code to the new code when it comes to making the AJAX request https://github.com/Hube2/acf-dynamic-ajax-select-example/tree/master/dynamic-select-example

  • The simple answer to your question is that this is extremely difficult to do without making many changes to the database. You have to find all of the fields in the DB and alter the meta key value to match the new name used by ACF.

    What you would need to do is to do a query on to get all posts, then loop over the post, get the old field value using get_post_meta() (because ACF will not be able to find this field using get_field()) then use update_field() to update the value of the new group field. If you have many posts this is likely to fail do to timing out. It can be done directly in the database but this would be prone to errors if the old field name is not unique.

    When I make interface changes of this nature I do the following
    (this is a quick explanation as there is a lot of code that would be involved)

    1. Create new field(s) – group and sub fields
    2. add an acf/prepare_field filter for the new sub field. If the new field does not have value (NULL) then populate the value with the old field value
    3. add an acf/save_post action that deletes the old value when a post us updated using the new field(s)
    4. add an acf/prepare_field filter to the old field that returns false to hide the old field but keep it definition intact
    5. In the template code where the field is used, get the new field value, if the value is NULL (never updated) then get the value from the old field

    This allows you to alter the field setup without needing to alter all of the existing data and will transition the fields from old to new as a post is updated. If a post is never updated then it will continue to work indefinitely.

  • If your gallery field is not a sub field of a group or repeater then the meta query would look something like this:

    
    'meta_query' => array(
      array(
        'key' => 'gallery_field_name',
        'value' => '"'.$attachment_id.'"',
        'compare' => 'LIKE'
      )
    )
    

    If it’s a sub field then it gets far more complicated, see the section on sub fields here https://www.advancedcustomfields.com/resources/query-posts-custom-fields/

  • Last Update: Now Works.

    I am uncertain as to why precisely or if I missed something important. However, for anyone reading this I installed the plugin “Classic Editor” and then redid the from group and now it works. I am not sure if it’s a requirement to have Classic Editor, maybe it is and I just haven’t read it in the guide or installation things etc. But it now works.

  • Third update:

    So I have no idea what is wrong or how to fix it. But it is now obvious that the actual problem is that the <?php $hero = get_field("hero");?> doesn’t actually get any values at all.

    I did this for simplicity:

    <?php $txt = "Hello world!";?>

    And then added it to the code html part as such:

    <h5><b><?php echo $txt ;?></b></h5>

    And it does come up as “Hello World” so it does work. Meaning the issue is that for some reason ACF groups doesn’t work or at least isn’t somehow connected meaning it doesn’t retrieve any values at all.

  • Second Update:

    After I did this code: <?php $hero = get_field("hero");?>

    I put in this code as seen on: https://www.advancedcustomfields.com/resources/get_field/
    To check if there are any values at all. Again I am new to this, ACF and PHP so I am hoping I did this part correctly.

    if( $hero ) 
    {
    echo $hero;
    } 
    else 
    {
    echo "empty";
    }
    ;?>

    By doing this, at the top of the page, below the header and above the section (see first post), it showed a gray bar with the word “Empty”. Meaning no values are being returned? So what am I doing wrong?

  • So update:

    There was a section that wasn’t working on the site and now it does. The errors that were listed above I fixed by changing:

    wp_register_script("jquery", get_template_directory_uri() . "/plugin-frameworks/jquery- 
     3.2.1.min.js", array(), 1, 1);
     wp_enqueue_script("jquery");
    

    To:

    
    wp_register_script("jQuery", get_template_directory_uri() . "/plugin-frameworks/jQuery-3.2.1.min.js", array(), 1, 1);
    wp_enqueue_script("jquery");
    

    Basically the same except the “jquery” needs to be “jQuery” with a capital Q. However the php part is still not showing anything. I can honestly say that I am not even sure the get_field(“hero”); is getting any results back at all. Not sure how to check it either.

  • Fair enough, but the header part works so I know PHP in itself works right?

    Nothing comes up or happens when I do the <?php print_r($hero); ?>, what is supposed to happen? I now also noticed when I inspect that it says an error to the far right (using Google Chrome):

    
    scripts.js?ver=1:46 Uncaught TypeError: $ is not a function
        at panelAccordian (scripts.js?ver=1:46)
        at scripts.js?ver=1:89
        at scripts.js?ver=1:138
    
    DevTools failed to load SourceMap: Could not load content for http://localhost/wpone/wp-content/themes/ThirdTheme/plugin-frameworks/maps/swiper.jquery.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE
    DevTools failed to load SourceMap: Could not load content for http://localhost/wpone/wp-content/themes/ThirdTheme/plugin-frameworks/bootstrap.min.js.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE
    DevTools failed to load SourceMap: Could not load content for http://localhost/wpone/wp-content/themes/ThirdTheme/plugin-frameworks/bootstrap.min.css.map: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE
    
    

    Why did this happen? Is this related?

    This is my functions.php:

    
    <?php
    
        function load_stylesheets(){
            
            // Everything from the Luigis template
            wp_register_style("font", get_template_directory_uri() . "/fonts/beyond_the_mountains-webfont.css", array(), 1, "all");
            wp_enqueue_style("font");
            
            wp_register_style("bootstrap", get_template_directory_uri() . "/plugin-frameworks/bootstrap.min.css", array(), 1, "all");
            wp_enqueue_style("bootstrap");
    
            wp_register_style("swiper", get_template_directory_uri() . "/plugin-frameworks/swiper.css", array(), 1, "all");
            wp_enqueue_style("swiper");
            
            wp_register_style("ionicons", get_template_directory_uri() . "/fonts/ionicons.css", array(), 1, "all");
            wp_enqueue_style("ionicons");
    
            wp_register_style("styles", get_template_directory_uri() . "/common/styles.css", array(), 1, "all");
            wp_enqueue_style("styles");
    
            // This is a custom stylesheet of CSS that you can use to override anything of the above.
            wp_register_style("custom", get_template_directory_uri() . "/custom.css", array(), 1, "all");
            wp_enqueue_style("custom");
    
        }
    
        add_action("wp_enqueue_scripts", "load_stylesheets");
    
        function load_js() {
            
            wp_register_script("jquery", get_template_directory_uri() . "/plugin-frameworks/jquery-3.2.1.min.js", array(), 1, 1);
            wp_enqueue_script("jquery");
            
            wp_register_script("bootstrapjs", get_template_directory_uri() . "/plugin-frameworks/bootstrap.min.js", array(), 1, 1);
            wp_enqueue_script("bootstrapjs");
    
            wp_register_script("swiperjs", get_template_directory_uri() . "/plugin-frameworks/swiper.js", array(), 1, 1);
            wp_enqueue_script("swiperjs");
    
            wp_register_script("scriptsjs", get_template_directory_uri() . "/common/scripts.js", array(), 1, 1);
            wp_enqueue_script("scriptsjs");
    
            wp_register_script("customjs", get_template_directory_uri() . "/customjs.js", array(), 1, 1);
            wp_enqueue_script("customjs"); 
        }
    
        add_action("wp_enqueue_scripts", "load_js");
    

    Did I do something wrong here? I am very lost..

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