Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • Oddly, I posted a followup post last night but it’s completely disappeared…..I still really need help with this please!

    I’ve monkeyed around with the code a bit, and now I have it where it displays ALL the repeater field values from the wp_postmeta table, regardless of the Post they are attached to – this is NOT what I want. I want just the values associated with the Post I’m viewing, on which the GF form appears.

    I have a Custom Post Type called “Resorts”, and on each Resort Page I have a repeater field to list the room types available for that resort (e.g. Deluxe, Suite, Oceanview, etc.). Each Resort has different room types.

    On the (front end) Resort Page, I can display those room types just fine along with the rest of the resort info. ALSO on that Page is a (Gravity) Form for the site visitor to choose a room type and dates and get a price quote. The “room types” is a drop-down field that is supposed to auto-populate with the values from the repeater field.

    SO the list of room types to choose from should be isolated to just that Resort – and it’s not, my drop down list is very long and includes ALL of the room types from ALL resorts…..aaargh!

    I am NOT a coder, just trying to piece this together using examples from this website that don’t really fit – the examples are mostly for showing ALL field values, such as the “Diplay all images” example.

    SO here is the code I’m using now – can someone PLEASE tell me how to modify this to ONLY show the repeater field values in the form dropdown from the one POST I’m viewing?

    add_filter("gform_pre_render_3", "dynamic_populate");
    
    function dynamic_populate($form) {
        foreach($form['fields'] as &$field){
         
            if(strpos($field['cssClass'], 'dynamicfield') === false)
                continue;
            //Condition : each field which has the class dynamicfield (example). If it doesn't then, continue ! Don't forget to add a class to the field you want to dynamically populate in your form. 
            
            global $wpdb;	
    	    $rows = $wpdb->get_results($wpdb->prepare( 
                "
                SELECT *
                FROM wp_postmeta
                WHERE meta_key LIKE %s 
                ",
    			'room_types_%_room_type'
            ));
                  
            $choices = array(array('text' => 'Select Room Type', 'value' => ' '));
            //Default choice for dynamic select field. Value is blank, so if it's required it won't validate.
            
            if( $rows ){
                foreach( $rows as $row ) {
                //If there are results, for each result, find the 'repeater row number'
                    preg_match('_([0-9]+)_', $row->meta_key, $matches);
    
                    $meta_key = 'room_types_' . $matches[0] . '_room_type';
                    $value = get_post_meta( $row->post_id, $meta_key, true );
                    //Get the subfield value from the row.
    
                    $choices[] = array('text' => $value, 'value' => $value);
                    //Create an option array for each subfield value.
                }  
            }
    
            $field->choices = $choices;
            //Once we've looped through all of the subfields values and created all of our options, we assign the $choices array (which has all of our new options) to the $field choices property.
    
        }
    
        return $form;
        //Display the new dynamically populated form.
    }
  • Hi @jasperrooduijn

    Thank you for the question.

    I believe you have to make use of the array_search() function. It returns the key of the element it finds, which can be used to remove that element from the original array using unset()

    The code will look something like this:

    if( ($key = array_search('code' , $toolbars['Full' ][2])) !== false )
    	{
    	    unset( $toolbars['Full' ][2][$key] );
    	}
  • Thanks for the responses. I’m actually on a dedicated server, so increasing the memory really does increase the memory. And yes, I’m sure that my max_input_vars and memory limit are correct by verifying in the php info.

    I added these:
    max_input_vars = 3000
    suhosin.get.max_vars = 3000
    suhosin.post.max_vars = 3000
    suhosin.request.max_vars = 3000
    Per the FAQ, although I bumped those all up to like 16000 with still no results. And memory is at 800MB currently.

    I was in the process of adding new fields when this started happening. I had to add 7 and I made it to 5 before it stopped working for the final 2. So I’m sure that no other plugins were updated or installed and I’m certain nothing else on the site was being changed either during the additions. It just decided to stop at 60 and making these changes hasn’t worked. I’ve also checked the database manually to be sure that it wasn’t some display issue, but the new entries I created (that ACF said were created successfully) are not in the database either. Thanks again.

  • Thi is how I solved it:

    <div class="dest-box">
    <div class="rk-row">
    <?php 
    $counter=1;
    $terms = get_terms( 'region' );
     if ( ! empty( $terms ) && ! is_wp_error( $terms ) ){
         echo '<div">';
         foreach ( $terms as $term ) {
    		 if ($term->parent > 0) { continue; }
    	   $term_link = get_term_link( $term );
    	   $image = get_field('region_image', $term->taxonomy . '_' . $term->term_id);
    	   $size = 'homepage-thumb';
    	   $thumb = $image['sizes'][ $size ];
    	$width = $image['sizes'][ $size . '-width' ];
    	$height = $image['sizes'][ $size . '-height' ];
    	   echo '<div class="col-md-6">';
    	   echo '<div class="destination-loop">';
    	   echo '<img src="' . $thumb . '"/>';
           echo '<h3><a href="' . esc_url( $term_link ) . '">' . $term->name . '</a></h3>';
    	   echo '<p>' . $term->description . '</p>';
    	   echo '</div></div>'; 
    	   
    	   
    		   if ($counter  == 2) {
      echo '<div class="clearfix"></div></div><div class="rk-row">'; 
      $counter=0;
    
    		} 
    			
         $counter++;        
         
    	 
    	 }
    	 
    	 
     }
     
     ?>
     <div class="clearfix">
    </div></div>
    
    </div>

    Thanks very much mate !

  • You can either change to an image object or ID for return values. My preference is ID but it depends on if I need more than one image size.

    If i’m only going to need one size I use ID and then wp_get_attachment_image_src() http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src.

    If I’m going to use multiple sizes the I have ACF return the image object.

    For using the image object you would use something like this

    
    $image = get_field('region_image', $term->taxonomy . '_' . $term->term_id);
    $src = $image['sizes'][$size];
    echo '<img src="' . $src .'"/>';
    

    You can see the entire image object to help you work on it by doing this:

    
    $image = get_field('region_image', $term->taxonomy . '_' . $term->term_id);
    echo '<pre>'; print_r($image); echo '</pre>';
    
  • (EDIT: This solution stopped working for me, but I found a new one with Elliot’s help. See my new comment.)

    PROBLEM SOLVED!!

    I found a solution.

    It’s not very pretty, but it certainly works. None of the filters I found in the source code offered a way to extend the arguments sent in a select2 ajax request.

    However, there is a filter to modify the select2 arguments. The annoying part is that the select2 arguments are actually a callback to an ACF function. So the magic here is that we replace that function with a “wrapper” function. This new function still calls the old function, then it adds the “Make” to the results. This data is then sent via ajax, and our filter can now show the correctly models!

    Here is the JavaScript, hard-coded by field ID for the MAKE:

    // Update the ajax arguments for select2 objects to include the Make value
    // This is done by replacing the default ajax.data function with a wrapper, which calls the old function and then appends "vehicle_make" to the results.
    acf.add_filter(
        'select2_args',
        function( args ) {
    
            if ( typeof args.ajax.data == 'function' ) {
                var old_data_func = args.ajax.data; // We'll keep this for maximum compatibility, and extend it.
    
                args.ajax.data = function(term, page) {
                    var default_response = old_data_func( term, page ); // Call the old, default function.
    
                    default_response.vehicle_make = function() {
                        // Add the vehicle make to the ajax function. This happens for all select 2 objects, even if it's blank.
                        return jQuery('#acf-field_55890984e822f').val();
                    };
    
                    // Return the default args with our vehicle_make function.
                    return default_response;
                }
            }
    
            return args;
        }
    );

    Here is the PHP Filter which limits the MODEL by term parent:

    function oss_filter_model_dropdown_admin( $args, $field, $post_id ) {
        // Look for the vehicle make in the AJAX request.
        $make = isset($_REQUEST['vehicle_make']) ? (int) $_REQUEST['vehicle_make'] : false;
    
        // If not found, use the previous vehicle's value.
        if ( $make === false ) $make = get_field( 'make_term', $post_id );
    
        // If no make has been selected, do not show any terms (-1 will never give results)
        // Otherwise, use the make as the parent term. Models are always a child of a make.
        if ( !$make ) $args['parent'] = -1;
        else $args['parent'] = (int) $make;
    
        return $args;
    }
    add_filter( 'acf/fields/taxonomy/query/name=model_term', 'oss_filter_model_dropdown_admin', 20, 3 );

    Here is a video demonstrating the end result, showing that the “Model” field’s options are directly tied to the “Make”.

    http://gfycat.com/RevolvingSleepyBarasingha

  • Thanks for the attempt John. I’ve already got the javascript file included properly, though I did not mention this.

    The problem with the second piece of code is that it does fire, but it fires after you select an option.

    Here is a demonstration: http://gfycat.com/IcyBaggyDore

    In that recording, I expect the console to log the event when the ajax data is prepared (as the filter name describes). This would allow me to say “hey ajax call, why don’t you take the value of MAKE with you!”.

    The problem though, is that it doesn’t fire immediately. It fires after you select an option.

    The reason this is a problem is because I want to filter what shows up in the dropdown, to do this I need to send that value when you click on the dropdown – when it is loading the results – so that I can access that value in my PHP filter (acf/fields/taxonomy/query/name=model_term)

    Here’s what SHOULD happen

    1. User clicks on dropdown
    2. Value of “Make” is added to ajax request
    3. Ajax request is fired, return a list of options
    4. Dropdown is populated with the returned options
    5. User selects one of the “Models” displayed, which are direct descendents of the “Make” from step 2.

    And here is what is CURRENTLY happening:

    1. User clicks dropdown
    2. The make is absent from AJAX request
    3. Ajax request is fired, but we cannot filter by the make
    4. Dropdown is populated with either ALL terms, or terms from the PREVIOUSLY SAVED MAKE.
    5. User is confused because either the wrong models are appearing, or a tremendous list (1300 items) is loaded.

  • 
    <?php 
    $args = array(
        'taxonomy'     => 'sock-club',
        'hide_empty'   => '0'
          );
    $terms = get_terms('sock-club', $args);
    if ($terms) {
        foreach ($terms as $index => $term) {
            $terms[$index]->star_rating = get_field('star_rating', $taxonomy.'_'$term_id);
          
        }
        usort($terms, 'my_sort_function');
        
        // create the list after the terms are sorted
        // need to loop through them again
        $term_list = '';
        foreach ($terms as $term) {
            $term_list .= '<a href="' . get_term_link( $term ) . '" title="' . sprintf( __( 'View all post filed under %s', 'my_localization_domain' ), $term->name ) . '">' . $term->name . '</a>';
        }
          
    }
    
    ?>
    
  • Hi @timothy_h

    Yep, looks like WP only searches the post_title and post_content.
    https://core.trac.wordpress.org/browser/tags/4.2.2/src/wp-includes/query.php#L2091

    You may need to hook into a filter to add a custom search to the SQL string. I believe WP contains some filters to modify the SQL, but I’m not sure off the top of my head.

    The get_terms function seems to search for name and slug, so this explains the difference. https://core.trac.wordpress.org/browser/tags/4.2.2/src/wp-includes/taxonomy.php#L1899

    Hope you can find a solution to extend the WP posts search and I hope to heave cleared up the difference

    Thanks
    E

  • I have my memory limit set to 800M and when I turn on debug, I get these 3 errors when I hit “Update” when trying to add an additional new field:

    Notice: wp_enqueue_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.) in /home/<domain>/public_html/wp-includes/functions.php on line 3560

    Notice: has_cap was called with an argument that is deprecated since version 2.0! Usage of user levels by plugins and themes is deprecated. Use roles and capabilities instead. in /home/<domain>/public_html/wp-includes/functions.php on line 3508

    Warning: Cannot modify header information – headers already sent by (output started at /home/<domain>/public_html/wp-includes/functions.php:3560) in /home/<domain>/public_html/wp-includes/pluggable.php on line 1196

    Any clues?

  • Thank you John,

    As a beginner I am still not able to get it working this way. This is the code I have:

    In my functions.php file:

        function my_sort_function($a, $b) {
            if ($a->star_rating == $b->star_rating) {
                return 0;
            } elseif ($a->star_rating < $b->star_rating) {
                return -1;
            } else {
                return 1;
            }
        }

    On my home page:

    <?php 
    $args = array(
        'taxonomy'     => 'sock-club',
        'hide_empty'   => '0'
          );
    $terms = get_terms('sock-club', $args);
    if ($terms) {
        foreach ($terms as $index => $term) {
            $terms[$index]->star_rating = get_field('star_rating', $taxonomy.'_'$term_id);
        
            $term_list .= '<a href="' . get_term_link( $term ) . '" title="' . sprintf( __( 'View all post filed under %s', 'my_localization_domain' ), $term->name ) . '">' . $term->name . '</a>';
          
        }
        usort($terms, 'my_sort_function');
    }
    
    ?>

    Can you see what is wrong with my code?

  • Not sure this will help but, this appears to be working. I don’t know that much about how this works to be honest, I used your JS and added it using the instructions here http://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/

    Only to discover that the script was not actually included anywhere in the page.
    Tried quite a few variations and found that setting a priority of 1 got it to load. And I can’t tell you why the script is not loaded without setting the priority.

    PHP

    
    function my_admin_enqueue_scripts() {
        wp_enqueue_script(
            'my_admin_script',
            get_template_directory_uri().'/js/test.js',
            array(),
            '1.1.0',
            true
        );
    }
    add_action('admin_enqueue_scripts', 'my_admin_enqueue_scripts', 1);
    

    JS File:

    
    acf.add_filter(
    	'prepare_for_ajax',
    	function(a,b,c) {
    		// This never gets triggered! :(
    		console.log('Filter args:', a,b,c);
    		return a;
    	}
    );
    
  • Hi @sebastianbotez

    You can’t run a php function in an onclick parameter on a button. That’s for javascript only. So you’ll either have to trigger a javascript function with the onclick parameter which in term does some AJAX in order for you to do the necessary php OR you’ll have to submit the form and let the function run if a POST parameter is set:

    
    
    <?php
    	
    if ( isset( $_POST['submit-playlist'] ) ) {
    
    	//Do your submit code in here
    	
    	$queried_object = get_queried_object();
    	$id = $queried_object->ID;
    	$name = $queried_object->post_title;
    	$poster = get_the_post_thumbnail($id);
    	$permalink = get_the_permalink($id);
    
    	$field_key = "field_558aaa2515415";
    	$user_ID = get_current_user_id();
    	$value[] = array("field_558ab367b4756" => "Playlistul meu", "field_558aaa626db89" => array("field_558ab1d98bcfe" => $permalink));
    	update_field( $field_key, $value, 'user_'.$user_ID );
    }
    
    ?>
    
    <form method="post">
    	<?php if ( isset( $_POST['submit-playlist'] ) ): ?>
    		<p>Thank you, your playlist has been submitted.</p>
    	<?php endif; ?>
    	<input type="hidden" value="<?php sanitize_text_field('submit-playlist'); ?>" name="submit-playlist" />
         <ul>
              <li>
                   <button type="submit" ><img src="<?php echo get_template_directory_uri(); ?>/images/playlist-icon.png" alt="">Playlist</button>
              </li>
         </ul>
    </form>
    
    
  • dear @elliot

    i tried to use the same code he did but i got nothing with my filed and i changed it to be post objects from page link this my code

       <?php
    
    $post_objects = get_field('related_products');
    //var_dump($post_objects);
    if( $post_objects ): ?>
        <?php foreach( $post_objects as $post_object): ?>
                <a href="<?php echo get_permalink($post_object->ID); ?>"><?php echo get_the_title($post_object->ID); ?></a>
        <?php endforeach; ?>
    <?php endif;
    	
    ?>

    so what should i do

    Regards

  • There is also this, which gives examples of building custom queries https://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query

    Unfortunately that also does not show how to do anything with related posts.

    To be honest, while I’ve had a lot of experience in the past with SQL, I’ve never tried to do custom queries like this and have always depended on WP_Query. I’m also finding that it has it’s limitations and have been trying to work out how to use it myself. I have a project coming up that’s going to require exactly what you’re doing.

    It will have a “Product” or “Inventory” post type and a “Specs” post type where each “Spec” can be associated with one or more products and then there will be a parametric search that searches these specs and show the products.

    But I have not found any information specific to this and I’ve been looking for a while. I’d say to ask over on the WP forums, you could get lucky, or maybe stack exchange http://wordpress.stackexchange.com/

    I’m going to be digging into this some more. If I figure anything out I’ll do my best to remember this discussion and post what I find.

  • I tried another approach by looping through the acf groups first, but without any luck. Check this one:

    $the_query = new WP_Query( array( 'post_type' => 'acf-field-group') );
    
    		// The Group Loop
    		if ( $the_query->have_posts() ) :
    		while ( $the_query->have_posts() ) : $the_query->the_post();
    		  $group_ID = get_the_ID();
    		  $name = get_the_title();
    
    		  echo '<p>Group ID: '.$group_ID.', Group name: '.$name.'</p>';
    
    		  $fields = array();
    		  $fields = apply_filters('acf/field_group/get_fields', $fields, $group_ID);
    		  
    		  if( $fields )
    		  {
    			  foreach( $fields as $field )
    			  {
    				  $value = get_field( $field['name'] );
    				  
    				  echo '<dl>';
    					  echo '<dt>' . $field['label'] . '</dt>';
    					  echo '<dd>' .$value . '</dd>';
    				  echo '</dl>';
    			  }
    		  } 
    
    		endwhile;
    		endif;
    		
    		// Reset Post Data
    		wp_reset_postdata();

    No matter what, $fields is always empty 🙁

  • Hi @sixtyseven

    There isn’t a way I know of to display all fields other than running a query on the wp_postmeta table yourself and discerning what’s an ACF field and what isn’t by testing or joining to the wp_posts table.

    But, if you have a particular ID of a page or post or options page that you want to get the custom fields for, you can use get_field_objects($postID); to get an array of fields along with various details about each field.

    You can then loop through them and use get_field('field_name', $postID); to get the value of a particular field if you need to show values too.

    I recently needed to do something similar to generate a ‘report’ which listed all custom fields and exported to a .csv – to do this, I first created a draft post with all custom fields filled in, saved it & used get_field_objects() for this post. I then took the resulting array & looped through it for each of the other posts to get the data. Perhaps not the most efficient way but it works.

    Hope this helps

    cheers
    alan

  • Ah that’s not fun… Looking over that, and being a front-end dev, SQL just blows my mind. I don’t suppose there’s any further light you could shed on how to go about selecting this from the DB? I’m struggling to even get the right posts to show up, let alone ones connected by related posts.

    Cheers.

  • Hi @daniel7912

    Thank you for the question.

    There is a plugin conflict interfering with the setting of the tinyMCE object in your category page. You should check to ensure that you identify the plugin bringing about the conflict by deactivating all other installed plugins and switching to one of the stock Wp themes.

    You can also try making the followng AJAX callback:

    $('.acf_wysiwyg textarea').each(function() {
        tinymce.execCommand('mceAddControl', false, $(this).attr('id'));
    });
  • This is a limitation of WP. You can’t do a query that looks for posts based on a meta fields of another post that is realated.

    post => related post => meta fields

    You might want to look at https://codex.wordpress.org/Class_Reference/wpdb

    to do something like this you’d need to construct your own queries.

  • Hi @owldesign

    Thank you for submitting this feature request.

    This information has been passed forth to the developer and hopefully this will see its way into the plugin sometime soon.

  • Hi @makeitminnesota,

    Thank you for the question.

    You can make use of the get_field_obejct function to return an array of the field object as seen in the field group edit screen.

    In your scenario, you can apply the function as follow:

    /*
    *  Get a field object and display it with it's value (using the field key and the value fron another post)
    */
    
    $field_key = "field_5039a99716d1d";
    $post_id = 123;
    $field = get_field_object($field_key, $post_id);
    
    echo $field['label'] . ': ' . $field['value'];

    You can have a look at this resource page for more info on this.

  • Hi @cecilehabran

    Thank you for the question.

    You can achieve this by hooking into the acf/fields/relationship/query filter. You can modify the $args array as follows:

    <?php
    
    function my_relationship_query( $args, $field, $post )
    {
        // increase the posts per page
        $args['posts_per_page'] = 25;
        $args['orderby'] = 'title';
        return $args;
    }
    
    // filter for a specific field based on it's name
    add_filter('acf/fields/relationship/query/name=my_select', 'my_relationship_query', 10, 3);
    
    ?>

    You can have a look at the following resource page

  • Hi @funkman733

    I am not confident that I have understood your question but if you are looking to get the server path for certain field using the File field, you can use a native WP function such as get_attached_file()

    You can then echo the values using the the_field(..) function.

  • Hi @bobitmonkey

    I ma not quite familiar with the working of the Atlas Listing theme but yo can get in touch with the guys over at themeforest.net for the right filters to hook into and then you can get to display the fields using the_field(..) and the get_field(..) functions.

Viewing 25 results - 16,551 through 16,575 (of 21,399 total)