Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • It looks like that plugin does post creation but not post editing/removing so it only solves half the problem.
    Do you know of a plugin that can add a new related post, edit and delete an existing related post. I’m after something like this Related Posts

    Thank you

  • thanks a lot John.
    I have this query to view the postmeta files that do not have any post relation

    SELECT * FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL

    But the query do not show only the advanced custom fields files.
    On the next query I have added the acf field to select only these fields

    SELECT * FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL AND pm.meta_key LIKE '%my-custom-field-name%'

    And now I would like to know if the query is correct and i can make the delete query without problems and errors on my wordpress after

    DELETE FROM wp_postmeta pm LEFT JOIN wp_posts wp ON wp.ID = pm.post_id WHERE wp.ID IS NULL AND pm.meta_key LIKE '%my-custom-field-name%'

  • Hi John,
    thanks for your answer! With your hints I figured it out. This is my solution:

    $date = get_post_meta( $entry->ID, "my-acf-field", true );
    $date = new DateTime($date);
    $finalVal =  $date->format('<\b/>j<\/b/><\b\r/>M'); 
    $output .= $finalVal;
  • Well, I’m not really sure what was going on. I tried to troubleshoot it and I made sure all content was entered in. the next day, more of the content was showing. Today, everything but the images on tab 4 were showing, so I went into the page, deleted all the images and re-inserted them, which didn’t help. I double checked the repeater images for that tab and set them to Required and then they started showing.


    @hube2
    thank you for trying to help. I’m still lost on this, but happy it’s working now.

  • Okay,

    I played around some more, and this seems to be a bug/inconsistency related to the ambiguous ways you can call wp_nav_menu, in particular the menu attribute you can pass in, which can be:

    (int|string|WP_Term) Desired menu. Accepts (matching in order) id, slug, name, menu object.

    Here the different output for different ways of calling my menu:
    wp_nav_menu(array('menu' => 'Footer menu'));
    results in print_r($args->menu):

    stdClass Object ( [menu] => Footer menu [container] => div [container_class] => [container_id] => [menu_class] => menu [menu_id] => [echo] => 1 [fallback_cb] => wp_page_menu [before] => [after] => [link_before] => [link_after] => [items_wrap] =>
    %3$s
    [item_spacing] => preserve [depth] => 0 [walker] => [theme_location] => )

    Where as this:
    wp_nav_menu(array('menu' => 1));
    results in print_r($args->menu):

    stdClass Object ( [menu] => WP_Term Object ( [term_id] => 3 [name] => Footer menu [slug] => footer-menu [term_group] => 0 [term_taxonomy_id] => 3 [taxonomy] => nav_menu [description] => [parent] => 0 [count] => 1 [filter] => raw ) [container] => div [container_class] => [container_id] => [menu_class] => menu [menu_id] => [echo] => 1 [fallback_cb] => wp_page_menu [before] => [after] => [link_before] => [link_after] => [items_wrap] =>
    %3$s
    [item_spacing] => preserve [depth] => 0 [walker] => [theme_location] => ) MENUWP_Term Object ( [term_id] => 3 [name] => Footer menu [slug] => footer-menu [term_group] => 0 [term_taxonomy_id] => 3 [taxonomy] => nav_menu [description] => [parent] => 0 [count] => 1 [filter] => raw )

    So apparently the menu will render with both methods, but the $args->menu differs significantly, and in the string parameter variant does not result in the term object ACF is expecting. Hurray WordPress.

  • The timeouts actually have to do with the browser. >30 seconds and browsers will generally show a timeout message. This can be an issue with ACF when there are a lot of fields to be saved without adding any overhead for adding the content to post_content. This is purely a case of the number of queries involved because WP only updates one meta value at a time and each update can take 2 to 4 db queries to complete. The first time I saw this issue was on a site where each layout had up to 7 wysiwyg fields. This site would time out just saving ACF data (without the extra processing) at around 10 to 15 layouts (as many as 135 wysiwyg editors), depending on how much content was being saved.

    Just a note that the timeout in this case will not cause the data to not be saved. Since there is no communication with the browser until php completes all the saving it completes before it knows that the browser has disconnected. When this happens you simply need to go back to the admin page and reload it to see all the changes. I supposed, it really extreme cases PHP could also timeout, depending on what your max execution time is, and that could cause an issue with the data actually being saved.

  • Hi John,
    thank you very much for the clear and huge explanation.

    At the moment the important task is to solve the question of putting the flexible content into the post_content.

    Actually I’m using the following solution that works very well for me. This solution is designed only for my pourposes but could be customized for other possible scenarios.

    function flexible_content_to_post_content( $post_id ) {
    
    	$post_type = 'books';
    
    	//Check if we are saving a books post type
    	if( get_post_type( $post_id ) != $post_type)
    		return;
    
    	//Check it's not an auto save routine
    	if( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) 
    		return;
    
    	//The Post Content
    	$post_content = '';
    	
    	//Loop the flexible content rows
    	if( have_rows('flexible_content') ):
    		while ( have_rows('flexible_content') ) : the_row();
    		
    			//TEXT BLOCK
    			if( get_row_layout() == 'text_block' ):
    				
    				$post_content .= get_sub_field('wysiwyg');
    	
    			endif;
    				
    		endwhile;
    	endif;
    	
    	
        //If calling wp_update_post, unhook this function so it doesn't loop infinitely
        remove_action('save_post', 'flexible_content_to_post_content');
    
    	// call wp_update_post update, which calls save_post again. E.g:
        wp_update_post(array('ID' => $post_id, 'post_content' => $post_content));
    
        // re-hook this function
        add_action('save_post', 'flexible_content_to_post_content');
    	
    }
    add_action('save_post', 'flexible_content_to_post_content');

    Thanks for sharing your plugin. At the moment the solution I’ve reported above is enough easy to use for me. I don’t need to check for all acf fields within the post. I need only to check text fields (textinput, textarea, wysiwyg) inside the flexible content.

    Of course I need to do some testing for large flexible fields, but considering my personal context, this should not be a problem.

    Thank you very much.

  • You should send these feature requests and ideas to the developer by opening a new support ticket https://support.advancedcustomfields.com/new-ticket/.

    There really is nothing that I can actually do put this into ACF except to suggest ways that it can be done using what ACF already offers. Like I said, I’m not involved in development of ACF or making decisions about what goes into it. The people that are don’t really read all the topics here, they depend on other users like us. The dev staff is small and if they read all the topics here they’d never get anything done.

  • If you want to move content to post_content for search it is very different than if you want to move content that can be displayed on another site.

    For search, all you need is the data of the field to be in the content and not formatted in any way. On the other hand, importing it into a site without ACF and being able to use it on another site without editing is completely different.

    The first is easier than the second.

    For the second you will need to loop through all of the fields when saved in the same way that you display the pages/posts on the front end of the site. You need to build all the html and content and then insert it into the post. This will be like building the front end of the site twice. More than likely this process will time out the admin of your site when saving posts if they have a large number of fields.

    There are two methods for the first, you could do the looping and put all the content into the content. This first method will have the same problems as trying to build the html content. The second method is to directly query the database to get all of the meta content from the post in just a few queries and then insert it. This is faster, but more complicated.

    Something else that you need to deal with is the fact that flex fields change and ACF does not update removed fields. Looping through the content and building it the same way as is done for the front end of the site avoids putting this stale data into the content. But then your back to dealing with the time involved to do the work. On the other hand, doing DB queries means that you need to find a way to remove that stale data or ignore it so that it’s not inserted into the content.

    Anyway, those are pretty much your options and I wanted you to have those before I gave a link to a plugin. This is a plugin that I’m working on to deal with the search issue and it is not meant to deal with the formatting issue in any way. It also only deals with text, textarea and wysiwig fields at this time because it’s all I am really concerned about. I probably won’t add other types of fields unless I have a need to. I feel that these 3 field types added to content will resolve 90% of the search problem. You are free to try it out or to look at my code to see how I’m doing this. It uses the second method of doing direct DB queries. I’ll let you read the rest there https://github.com/Hube2/acf-to-content

  • I am having trouble getting this to work. I am able to enqueue the script, but I am not sure where or how to check if it is loading after ‘acf-input’ is loaded as you said.

    here is my code:

    // set end date from start date
    
      var start_date_key = 'field_55b9e422a0ec5'; // the field key of the start date
      var end_date_key = 'field_56274f2898327'; // the field key of the end date
    
      if (typeof(acf) != 'undefined') {
        // add an action for all datepicker fields
        acf.add_action('date_picker_init', function($input, args, $field) {
          // get the field key for this field
          var key = $input.closest('.acf-field').data('key');
          // see if it's the start date field
          if (key == start_date_key) {
            // add action to start date field datepicker
            $input.datepicker().on('input change select', function(e) {
              // get the selected date
              var date = jQuery(this).datepicker('getDate');
              // add 5 days to date
              date.setDate(date.getDate()+5);
              // set end date
              jQuery('[data-key="'+end_date_key+'"] input.hasDatepicker').datepicker('setDate', date);
            });
          }
        });
      }

    and in functions.php:

    add_action('acf/input/admin_enqueue_scripts', 'enqueue_date_script');
    function enqueue_date_script() {
    	wp_enqueue_script('date-picker', '/date-picker.js', array('acf-input'));
    }

    Am I missing something here? I have ensured that the field keys are correct. I am using ACF 5.3.0

  • Just a quick update. For an upgrade-proof workaround, just save the entire contents of the file I posted earlier in this thread to your theme and use require_once within your functions.php file.
    require_once 'class-acf-location-post-template.php
    It will override the built in one and provide the fix.

  • I think you may be something else incorrect, but I can’t tell what it is from what you’ve provided.

    When using this

    
    add_filter('wp_nav_menu_items', 'my_wp_nav_menu_items', 10, 2);
    
    function my_wp_nav_menu_items( $items, $args ) {
    
    ...
    

    $args->menu should be a term object. When I add this filter and do print_r($args) I get this:

    
    stdClass Object
    (
      [menu] => WP_Term Object
        (
          [term_id] => 30
          [name] => manue 1
          [slug] => manue-1
          [term_group] => 0
          [term_taxonomy_id] => 30
          [taxonomy] => nav_menu
          [description] => 
          [parent] => 0
          [count] => 7
          [filter] => raw
        )
    
      [container] => div
      [container_class] => 
      [container_id] => 
      [menu_class] => nav-menu
      [menu_id] => primary-menu
      [echo] => 1
      [fallback_cb] => wp_page_menu
      [before] => 
      [after] => 
      [link_before] => 
      [link_after] => 
      [items_wrap] => <ul id="%1$s" class="%2$s">%3$s</ul>
      [item_spacing] => preserve
      [depth] => 0
      [walker] => 
      [theme_location] => primary
    )
    

    Looking at this https://www.advancedcustomfields.com/resources/adding-fields-menu-items/

    
    add_filter('wp_nav_menu_objects', 'my_wp_nav_menu_objects', 10, 2);
    
    function my_wp_nav_menu_objects( $items, $args ) {
    
    ...
    

    $args results in the same.

    Probably a little known fact, but $post_id when calling ACF functions can also be an object of type post, term or user.

  • I created a acf ticket but don’t have a link to it yet.
    For my situation a post template makes sense. I created an online training system where each lesson is comprised of a series of Topics which are custom post types. Some topics include a piece of audio which requires its own acf group. Being able to leverage all of the core topic logic and yet create an alternative version via a template is a perfect solution.

  • Many thanks for Your advise 🙂

    My working code is

    <?php
    			// check if the repeater field has rows of data
    			if( have_rows('zdjecia') ):
    			// loop through the rows of data
    			while ( have_rows('zdjecia') ) : the_row();
    			// display a sub field value ?>
    			<div class="entry-thumb">
    			<?php
    			$image = get_sub_field('zdjecie', false);
    			$size = 'sydney-large-thumb'; // (thumbnail, medium, large, full or custom size)
    			if( $image ) {
    			echo wp_get_attachment_image( $image, $size );}
    			?>
    			</div>
    			<?php endwhile;
    			else :
    			// no rows found
    			endif;?>
  • I was able to modify /includes/locations/class-acf-location-post-template.php with a workaround. I’ll post the whole file here for clarity. I added a class method acf_location_post_template::acf_get_post_templates() then changed both calls to the native get_post_templates()

    
    <?php 
    
    if( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
    
    if( ! class_exists('acf_location_post_template') ) :
    
    class acf_location_post_template extends acf_location {
    	
    	
    	/*
    	*  __construct
    	*
    	*  This function will setup the class functionality
    	*
    	*  @type	function
    	*  @date	5/03/2014
    	*  @since	5.0.0
    	*
    	*  @param	n/a
    	*  @return	n/a
    	*/
    	
    	function initialize() {
    		// vars
    		$this->name = 'post_template';
    		$this->label = __("Post Template",'acf');
    		$this->category = 'post';
    		$this->public = acf_version_compare('wp', '>=', '4.7');
        	
    	}
    	
    	
    	/*
    	*  get_post_type
    	*
    	*  This function will return the current post_type
    	*
    	*  @type	function
    	*  @date	25/11/16
    	*  @since	5.5.0
    	*
    	*  @param	$options (int)
    	*  @return	(mixed)
    	*/
    	
    	function get_post_type( $screen ) {
    		
    		// vars
    		$post_id = acf_maybe_get( $screen, 'post_id' );
    		$post_type = acf_maybe_get( $screen, 'post_type' );
    		
    		
    		// post_type
    		if( $post_type ) return $post_type;
    		
    		
    		// $post_id
    		if( $post_id ) return get_post_type( $post_id );
    		
    		
    		// return
    		return false;
    		
    	}
    	
    	
    	/*
    	*  rule_match
    	*
    	*  This function is used to match this location $rule to the current $screen
    	*
    	*  @type	function
    	*  @date	3/01/13
    	*  @since	3.5.7
    	*
    	*  @param	$match (boolean) 
    	*  @param	$rule (array)
    	*  @return	$options (array)
    	*/
    	
    	function rule_match( $result, $rule, $screen ) {
    		
    		// vars
    		$templates = array();
    		$post_id = acf_maybe_get( $screen, 'post_id' );
    		$page_template = acf_maybe_get( $screen, 'page_template' );
    		$post_type = $this->get_post_type( $screen  );
    		
    		// bail early if no post_type found (not a post)
    		if( !$post_type ) return false;
    		
    		
    		// get templates (WP 4.7)
    		if( acf_version_compare('wp', '>=', '4.7') ) {
    			
    			// $templates = wp_get_theme()->get_post_templates();
    			$templates = $this->acf_get_post_templates();
    			
    		}
    		
    		
    		// 'page' is always a valid pt even if no templates exist in the theme
    		// allows scenario where page_template = 'default' and no templates exist
    		if( !isset($templates['page']) ) {
    			
    			$templates['page'] = array();
    			
    		}
    		
    		
    		// bail early if this post type does not allow for templates
    		if( !isset($templates[ $post_type ]) ) return false;
    		
    		
    		// get page template
    		if( !$page_template ) {
    		
    			$page_template = get_post_meta( $post_id, '_wp_page_template', true );
    			
    		}
    		
    		
    		// new post - no page template
    		if( !$page_template ) $page_template = "default";
    		
    		
    		// match
    		return $this->compare( $page_template, $rule );
    		
    	}
    	
    	
    	/*
    	*  rule_operators
    	*
    	*  This function returns the available values for this rule type
    	*
    	*  @type	function
    	*  @date	30/5/17
    	*  @since	5.6.0
    	*
    	*  @param	n/a
    	*  @return	(array)
    	*/
    	
    	function rule_values( $choices, $rule ) {
    		
    		// vars
    		$choices = array(
    			'default' => apply_filters( 'default_page_template_title',  __('Default Template', 'acf') )
    		);
    		
    		
    		// get templates (WP 4.7)
    		if( acf_version_compare('wp', '>=', '4.7') ) {
    			// $templates = wp_get_theme()->get_post_templates();
    			$templates = $this->acf_get_post_templates();
    			$choices = array_merge($choices, $templates);
    		}
    		
    		
    		// return choices
    		return $choices;
    		
    	}
    
    	function acf_get_post_templates() {
    		$post_types = acf_get_post_types(array(
    			'exclude'	=> array('attachment')
    		));
    		$post_templates = array();
    		foreach ($post_types as $post_type) {
    			if ( $files = wp_get_theme()->get_page_templates(null, $post_type) ) {
    				if ( ! isset( $post_templates[ $post_type ] ) ) {
    					$post_templates[ $post_type ] = array();
    				}
    				$post_templates[ $post_type ] = $files;
    			}
    		}
    		return $post_templates;
    	}
    	
    }
    
    // initialize
    acf_register_location_rule( 'acf_location_post_template' );
    
    endif; // class_exists check
    
    ?>
    
  • Ok thanks @hube2. I had assumed a ticket already existed for this.

    I did some digging and turns out it might be a bug in WP. ACF uses wp_get_theme()->get_post_templates(); to get available templates as it probably should but WP_Theme::get_post_templates() fails to request files from the parent theme folder and there are no params or hooks to force it to.
    I created a ticket on trac. https://core.trac.wordpress.org/ticket/41717

    Going to take a shot at a workaround and I’ll submit here and in a new ticket if it works.

  • It depends on what version of ACF you’re using. There is a custom format for the display formatting. In ACF4 it says you can use any valid jquery date format. For ACF5 it uses the builtin WP function date_i18n() https://developer.wordpress.org/reference/functions/date_i18n/ and you can use any valid date formatting string.

    If this does not work for you then you’ll need to get the unformatted value of the field get_field('field_name', false, false); and format it yourself using PHP.

  • Just speaking in general as I’m not the developer and do not know his thinking on this.

    
    array(
    ‘areacode’ => ‘888’,
    ‘prefix’ => ‘123’,
    ‘linenumber’ => ‘4567’,
    ‘extension’ => ‘300’,
    );
    

    is great in the US, but is not consistent the world over. I know from experience attempting to validate phone numbers that people enter that it pretty much impossible to account for every way that phone numbers are used in the world. Unlike many things, there isn’t an international standard for phone numbers. Any validation of a phone number would have to be done based on need. Even the html element <input type="tel" /> does not validation numbers unless you provide the pattern to validate against https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/%3Cinput_type=_tel_%3E. My guess is that this is a part of the reason there is no telephone field in ACF.

  • Every field in ACF has a field key. It is unique for every field created and remains the same. The reason for this is that field names can be duplicated. ACF uses the field keys in instead of the names in all of it’s forms. When editing a field group you can see the field keys if you click on Screen Options in the upper right and then check Field Keys.

    The validation for the ACF field is included on the user registration form, but you have to build your own validation filter. https://www.advancedcustomfields.com/resources/acf-validate_value/

  • The validate function would be a great solution – however, this custom field is injected in the user registration form, so it doesn’t seem to trigger the validation functions.

    I could be wrong (maybe misconfigured function) but if I’m right, you might want to consider hooking your validation function into the registration form, since adding fields to the user_form = registration is a built-in feature of your system.

    I was able to validate the field (and trigger the native WP registration errors) through the registration_errors() hook. However, that brings me to a different problem.

    When I var_dump the $_POST variable in this function, it includes the data I want, but it’s attached to an obscure field_ key:

    array(10) {
      ["user_login"]=>   string(11) "johnsmith"
      ["user_email"]=>   string(23) "[email protected]"
      ["_acf_post_id"]=>   string(6) "user_0"
      ["_acf_nonce"]=>   string(10) "8294e063ae"
      ["_acf_validation"]=>   string(1) "1"
      ["_acf_ajax"]=>   string(1) "0"
      ["_acf_changed"]=>   string(1) "1"
      ["acf"]=>
      array(1) {
        ["field_5999b7f405d29"]=>
        string(11) "Candlestick Maker"
      }
      ["redirect_to"]=>   string(27) "https://example.com/welcome"
      ["wp-submit"]=>   string(8) "Register"
    }

    I can validate that field (in your solution, check against “not allowed”). But I’m unclear on how to access this field_ key value (in this case, “field_5999b7f405d29“). I can do a var_dump like this and see it, I could reverse engineer it from the database, but is there a way to get that key that’s more intuitive and portable?

    * Note the user_ ID is not established at this point, so I can’t, for example, access the field like so:

    get_field('occupation', 'user_22');

  • John,

    Thanks for the reply. After much tinkering I figured out that I need to include the have_rows loop in the functions.php to obtain the desired sub_field data. But the issue is that when I pass that data over to my variable as an array, I get all the urls concatenated as one string. This only happens when a page has multiple rows not when there is only 1.

    Since this is more of a general PHP question and not ACF specific, I’ll mark your replay as the solution.

  • The question I have is why do you want to put the values of the fields into post_content?

    and do you want this content to be formatted for display?

  • I just solved it myself:

    Because of the animation that happens on the removal of a repeater row, there is a 250ms delay before the values are removed.

    by using .on('remove', function()) from jquery-ui the problem is gone.

    here is my working code:

    $j("." + currenttab + i).on("remove", function () {
       calculate_subtotal(currenttab);
    })

    Thank you for your help!

  • I don’t have a solution because I have not experienced the problem, but I do have some questions.

    What version of PHP is running on the servers where the relationship is not saving?

    Do you have an issue with other field types that save serialized data, for example multis select, taxonomy or user fields?

Viewing 25 results - 10,801 through 10,825 (of 21,317 total)