Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • Usually, when this happens, it means that a PHP error occurred on the server during the AJAX request.

    If you’re still experiencing this problem. Can you enable error logging on your production server? If you can then try the action and see what, if any PHP errors are logged during the request. This will help me diagnose what the problem might be.

  • Section 4 of this How To give an example of querying posts by a repeater sub field. http://www.advancedcustomfields.com/resources/query-posts-custom-fields/

  • Hey there, for anyone that is wondering as well.

    ACF does use add_query_arg(), but neither of the two places this is used depends on user input. The vulnerability reported by Sucuri was has to do with using user input without escaping it when using this function.

    ~JH

  • ACF allows you to create your own location rules http://www.advancedcustomfields.com/resources/custom-location-rules/

    It should be possible to create a rule that checks to see if a category is selected of not. You could add a rule for “Category” “does not equal” “empty”.

  • Thanks for replying James. Sorry it took so long for me to view this. Here is what is happening:

    I have a repeater setup on our corp. site. It’s a list of all of our resources. In the ACF in WordPress, I have a Repeater (resources) that has 11 sub-fields. A few of the resources are videos, so I have javascript functions that allow for lightbox video views. For the resources that are videos, I have conditional logic setup in the ACF in WordPress that says if Type is equal to video, show these 4 fields. When I fill out the forms on the WordPress page, everything looks good at this point. If I select type equal to video, the appropriate 4 fields show and I can enter the values.

    The problem is once this WordPress page is saved and I view the page, some of the other resources that are not videos have the javascript code associated with them. I thought I had it setup correct but obviously not. My php logic was to show the javascript code only if a value existed. Since all the resources that aren’t videos don’t have a particular field value, I thought that would work. Below is the actual code from the page:

    <?php if( have_rows('resources') ): ?>
            <ul id="Resource-Grid" class="list-unstyled">
              <?php while( have_rows('resources') ): the_row(); 
    				  
    				  // vars
    					$date = get_sub_field('date');
    					$featured = get_sub_field('featured');
    					$type = get_sub_field('type');
    					$topic = get_sub_field('topic');
    					$data_date = get_sub_field('data_date');
    				 	$link = get_sub_field('link');
    					$image = get_sub_field('image');
    					$title = get_sub_field('title');
    					$icon = get_sub_field('icon');
    					$download_label = get_sub_field('download_label');
    					$label_type = get_sub_field('label_type');
    
    					$embed_code = get_sub_field('embed_code');
    					$link_id = get_sub_field('link_id');
    					$function_id = get_sub_field('function_id');
    					$variable_id = get_sub_field('variable_id');
    					
    					?>
              <li data-date="<?php echo $data_date; ?>" class="mix <?php echo $topic; ?> <?php echo $type; ?> <?php echo $featured; ?> col-sm-6 col-lg-4">
    
                <?php if( $embed_code ): ?>
                <script type="text/javascript" id="vidyard_embed_code_<?php echo $embed_code; ?>" src="//play.vidyard.com/<?php echo $embed_code; ?>.js?v=3.1&type=lightbox"></script> 
                <script type="text/javascript">
    			window.onload = function() {
        				var <?php echo $variable_id; ?> = document.getElementById("<?php echo $link_id; ?>");
         				<?php echo $variable_id; ?>.onclick = function() {
         					fn_vidyard_<?php echo $function_id; ?>();
         					return false;
          				}
            		}
        		</script>
                <?php endif; ?>
              
                <a <?php if( $embed_code ): ?> id="<?php echo $link_id; ?>" onclick="fn_vidyard_<?php echo $function_id; ?>();" <?php endif; ?> href="<?php echo $link; ?>" target="_blank">
                <div class="resource-item">
                  <div class="resource-img-container">
                    <div class="resource-overlay"><span class="btn btn-small white-outline"><i class="fa fa-<?php echo $icon; ?>"></i> <?php echo $download_label; ?> <?php echo $label_type; ?><span></div>
                    <img src="<?php echo $image; ?>" alt="" class="img-responsive"></div>
                  <div class="resource-content">
                    <div class="resource-date"><?php echo $date; ?></div>
                    <div class="resource-type"><?php echo $type; ?></div>
                    <p class="resource-title"><?php echo $title; ?></p>
                  </div>
                </div>
                </a> </li>
              <?php endwhile; ?>
            </ul>
            <?php endif; ?>

    Using Developer Tools, here is what is showing in the rendered HTML for a resource whose type is NOT equal to video:

  • Hi @ashkas

    First off nice use of gazumped 🙂

    It’s a strange issue you have. I have some questions for you:

    1. Does this only happen on terms? Not posts/pages?
    2. Do you have any other field or maybe post/page with the same “slug” (plate)?
    3. Did you create these fields directly from within wp-admin? (Not php or json).
    4. If you actually check your database wp_options table for this value, does it say “something”?

  • I see why those are there and it makes sense. But in my case, I have several different field groups with fields that have the same name and I’m styling them all the same way. In this example, they each require a physical address.

    If I could write: “.acf-field-name-city” and style all of my “city” fields across all of my forms at once, that would be great. It also makes my CSS much more readable, and applies the style to additional forms I might make in the future.

    I realize I could specifically add a class to the field data, but that’s an extra step and I’m duplicating data I’ve already entered.

    As for the field name changing: sure it could change, but that also means changing the PHP code supporting it. (I’m asking for the name to be output here, not the label.)

  • Hi @netfreak

    I understand why you have issues! loading a hundred maps on a single page is going to be slow and really not something one want to encounter..

    I think that rather than this being an issue with ACF it’s an issue of architecture. Do you really need all of these at an options page? It would seem a better solution is to create a custom post type and place a single map for each post. Then you will only load one map for each post in admin. There’s also the advantages of being able to utilize wp_query for either simple queries or to fetch only specific maps easily. You’ll also get a much more approachable admin interface with search capabilities, ability to sort by date etc. etc.

    My suggestion is thus to not try to patch up a leaky ship but change it completely instead.

  • Hi @moettinger

    That’s a tough one.Sub field values are saved to wp_postmeta etc. in this way: repeater_field_name_0_sub_field_name with 0 ticking upwards with each row.

    With an repeater inside another repeater I think it’ll be:
    repeater_field_name_0_sub_repeater_field_name_0_sub_field_name

    Since you now initially want to put your repeater in another repeater I’m assuming the whole current repeater should go as the first row (I.E. 0).
    You’d probably have to do some clever SQL queries to change the values of each repeater_field_name_0_sub_field_name into repeater_field_name_0_sub_repeater_field_name_0_sub_field_name

    but you’ll also first have to make sure atleast 1 row has been previously created in the root repeater. If you check the DB you’ll see that the repeater fields only contain a count (starting at 1) of how many rows they contain so just running an SQL for the above will not cause the values to show up.

    Hope I got you started! It’s not an easy topic to tackle 🙂

  • Hi Hazard,

    Thanks for noticing! I think the reason for the message field type using a label like all the other field types is because there’s some styling to the label element.

    I’ll be sure to make an improvement request for this for future updates!

  • Thanks for the heads-up on the Gallery field Jonathan, but my website’s gallery is quite complex, requiring a few checkbox custom fields to control things like cropping for each image. Hence why I’m using the Repeater plugin.

  • The first print_r() results I posted is after the attempt to translate.
    if I edit the post in the admin and save it and then load that post in the front end it is still not working.
    It start to work only after form submission.
    I discover that the problem is in api-filed.php in function _acf_get_field_by_id (starts around line 916).

    First time the page with the form is loaded

    // get post
    	$post = get_post( $post_id );

    return translated values instead of full string values in this way:

    WP_Post Object
    (
        [ID] => 655
        [post_author] => 1
        [post_date] => 2015-06-17 12:25:15
        [post_date_gmt] => 2015-06-17 10:25:15
        [post_content] => a:12:{s:4:"type";s:4:"text";s:12:"instructions";s:99:"(nome e numero della strada)";s:8:"required";i:1;s:17:"conditional_logic";i:0;s:7:"wrapper";a:3:{s:5:"width";i:50;s:5:"class";s:0:"";s:2:"id";s:0:"";}s:13:"default_value";s:3:"azz";s:11:"placeholder";s:0:"";s:7:"prepend";s:0:"";s:6:"append";s:0:"";s:9:"maxlength";s:0:"";s:8:"readonly";i:0;s:8:"disabled";i:0;}
        [post_title] => indirizzo
        ........
    )

    instead of the correct way which is this one:

    WP_Post Object
    (
        [ID] => 655
        [post_author] => 1
        [post_date] => 2015-06-17 12:25:15
        [post_date_gmt] => 2015-06-17 10:25:15
        [post_content] => a:12:{s:4:"type";s:4:"text";s:12:"instructions";s:99:"[:it](nome e numero della strada)[:en](name and number of street)[:fr](nom et numéro de la rue)[:]";s:8:"required";i:1;s:17:"conditional_logic";i:0;s:7:"wrapper";a:3:{s:5:"width";i:50;s:5:"class";s:0:"";s:2:"id";s:0:"";}s:13:"default_value";s:3:"azz";s:11:"placeholder";s:0:"";s:7:"prepend";s:0:"";s:6:"append";s:0:"";s:9:"maxlength";s:0:"";s:8:"readonly";i:0;s:8:"disabled";i:0;}
        [post_title] => [:it]indirizzo[:en]address[:fr]adresse[:]
        ........
    )

    and which is the way $post object is correctly returned after form submission

    In that way inside the _acf_get_field_by_id function

    // unserialize
    	$data = maybe_unserialize( $post->post_content );

    returns a boolean instead of an array due unserialization which gets error while parsing the uncorrect
    s:99:"(nome e numero della strada)";

    of course: the string length is 28 chars and not 99!

  • Hi John,

    Cheers for the help, I didn’t realise acf have a form. I solved it another way, by using ajax.

    <?php 
    	// This allows our page to have wordpress knowledge
    	define('WP_USE_THEMES', false);
    	require_once('../../../wp-load.php');
    	
    	$userid = $_REQUEST['userid']; 
    	$email = $_REQUEST['email'];  
    	$username = $_REQUEST['username']; 	
    	$pageid = $_REQUEST['pageid']; 	
    	$attendFB = $_REQUEST['attendFB']; 
    	
     $update_field = new WP_Query('showposts=1&post_type=tribe_events&orderby=date&order=ASC&p='.$pageid );
    					while ($update_field->have_posts()) : $update_field->the_post();
    					the_title();
    	//get attending rows
    	if( have_rows('attending') ){
    		$gallery = get_field( 'attending' );
    	} else {
    		$gallery = array();
    	}
    	// add to existing array
    	$gallery[] = array(
    		'user_id'		=> $userid,
    		'name'	=> $username,
    		'email'	=> $email
    	);
    	// save new array
    	update_field("field_identifier", $gallery, get_the_ID());
    
    	endwhile;  wp_reset_query(); 
    	?>
  • That seems to do the trick:

    function my_post_object_query( $args )
    {
        $args['author'] = get_current_user_id();
    
        return $args;
    }
    
    add_filter('acf/fields/post_object/query/name=my_post_object_field_name', 'my_post_object_query', 10, 3);

    ACF rocks!!

  • I think I’m almost there using a custom filter function in functions.php

    function my_post_object_query( $args )
    {
    
        $args['author'] = '2';
    
        return $args;
    }
    
    add_filter('acf/fields/post_object/query/name=my_post_object_field_name', 'my_post_object_query', 10, 3);

    The only thing I need to figure out is, how to dynamically set the ID to the current user/author.

  • updated (better) version with prepend and append elements and support for regular text input fields and without extra function:

    function make_cells($field){
    	global $post, $posts;
    	$i = 1; // variable counter, may reset during foreach
    	$b = 1; // global counter, never resets
    	$end = count($posts);
    	echo "<td";
    	foreach($posts as $key => $post) {
    		$value = get_field($field);
    		$valueobj = get_field_object($field);
    		$nextvalue = "";
    		if(isset($posts[$key+1]))
    			$nextvalue = get_field($field,$posts[$key+1]->ID);
    		if($nextvalue != $value){ 
    			echo " colspan='".$i."'>";
    			if(isset($valueobj["prepend"])) echo $valueobj["prepend"]." ";
    			if(isset($valueobj["choices"])){
    				if(is_array($value)){
    					$newarray = [];
    					foreach($value as $val){
    						$newarray[] = $valueobj["choices"][$val];
    					}
    					echo implode(", ",$newarray);
    				}else{
    					echo $valueobj["choices"][$value];
    				}
    			}else{
    				echo $value;
    			}	
    			if(isset($valueobj["append"])) echo " ".$valueobj["append"];
    			$i=0; 
    			if($b != $end) echo "</td><td";
    		} 
    		if($b == $end) echo "</td>";
    		$i++;
    		$b++;
    	}
    }
  • Hi @Jonathan.

    There is no difference.
    When I export the working page_link element from the GUI I get this code:

    array (
        'key' => 'field_557ff199ab6a8',
        'label' => 'Link_aus_GUI',
        'name' => 'link_aus_gui',
        'type' => 'page_link',
        'instructions' => '',
        'required' => 0,
        'conditional_logic' => 0,
        'wrapper' => array (
            'width' => '',
            'class' => '',
            'id' => '',
        ),
        'post_type' => array (),
        'taxonomy' => array (),
        'allow_null' => 0,
        'multiple' => 0,
    ),
  • Hi @ninjamonk

    Thanks for the info, but I don’t quite understand.

    What do you mean by:
    The problem is to recreate it I need to install the broken plugin on a live site.
    – What is the broken plugin?
    – What is the problem?

    Were you able to watch the AJAX request to validate the data?
    – Did the AJAX request ever return data? If so, what was the data?

  • Have you read this tutorial on relationships and doing reverse relationship queries?

    It this does not cover your situation and you’re still looking for help, please provide more detail on what you’re trying to accomplish.

  • Thanks for the feature request. I will bring this to the attention of the developer.

  • Thanks for the feature request. I’ll bring this to the developer’s attention.

    Just as a note, I can see at least one reason why this is not already a feature. Everything depends on this field key.

    If Elliot gave people the ability to change the field key they would then expect that changing the key would also change all of the rows in the postmeta and options tables as well so that no data was lost.

    While I don’t think that allowing the field keys to be changed would be difficult; searching, finding and updating all the references to the field key would be a major project, and depending on the size of the site and the amount of db queries needed, it could potentially fail before it was completed.

    ~JH

  • There are filters hooks that are run before the posts are queried. This hook is documented here http://www.advancedcustomfields.com/resources/acf-fields-post_object-query/ and you can use this to change the order that posts are returned

  • Hey, not sure if you still need help with this, trying to clean up some old questions. I don’t really have an answer for the way you are attempting to do this, but I do have a suggestion for an easier way to do this. I try to do things in the simplest way so that I can get it done faster.

    If I were to attempt to do this I would load an iframe into the modal window. I’d create a special template that had only what was needed to make the page and acf_form() work.

    Then you can use acf/pre_save_post or even acf/save_post hooks to do whatever you want to do with the posted data, including put it somewhere else.

  • This isn’t something that ACF will do automatically, you’ll need to handle this with your query and loop.

    WP 4.0 and 4.2 introduced better ordering.

    For the latest change, see this post: https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query/

    As for the enhanced orderby see the orderby section codex page for WP_Query or this post: https://make.wordpress.org/core/2014/08/29/a-more-powerful-order-by-in-wordpress-4-0/

    First you need to get them ordered correctly. This will output them in the right order, then you can create a custom loop that will do the work.

    Here is an example of a simple loop that will do the separating.

    
    $last_brand = '';
    $this_brand = '';
    while (have_poste()) {
        the_post();
        $this_brand = get_field('brand');
        if ($this_brand != $last_brand) {
            // change brands
        }
        $last_brand = $this_brand;
        // rest of the loop here
    }
    
  • Honestly, I don’t know what’s going on either, basically I’m stabbing in the dark.

    I have some more question though.

    The first print_r() results you posted. Is that before or after the attempt to translate?

    You said that before the post is submitted it’s not working but after it is working. What happens if you edit the post in the admin and save it and then load that post in the front end? Is it still not working?

Viewing 25 results - 16,651 through 16,675 (of 21,397 total)