Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • Hi,

    If you have a select field without multiple select it should just return a value not an array..

    This code might get you in the right direction:

    
    <?php 
    $activity_rating = get_field('activity_rating');
    
    switch($activity_rating){
    	
    	case '1':
    		$img = 'urltoimage';
    		break;
    	case '2':
    		$img = 'urltoimage2';
    		break;
    	case '3':
    		$img = 'urltoimage3';
    		break;
    	case '4':
    		$img = 'urltoimage4';
    		break;
    	case '5':
    		$img = 'urltoimage5';
    		break;
    	case default:
    		$img = 'fallbackimage';
    		break;
    		
    	echo '<img src="' . $img . '" alt="" />';
    	
    }
    ?>
    
  • Hi @powcom,

    Natively the answer is no. There’s no way to do that.
    However you could create your own plugin for this.

    Create a custom admin page. In it you do a wp_query for all posts (or any post type) which contains the data you want to be able to edit. Output them as a table list with the inputs you need (this could get tricky if you have many different field types but if it’s just inputs, editors etc. it would be fairly simple. Then on posting your custom form table just do the logic necessary to update each posts information.

    I think this would be a pretty great idea for a third party plugin. The biggest issue that I can think of is how to make it dynamic.. One would probably want to be able to set in some settings which field groups to do the wp_query on or maybe do it dynamically on the custom admin page before the wp_query even runs.

  • Hi,

    Are the second image of the field group admin?
    There are quicklinks for the necessary actions in the latest versions of ACF.

    actions like “view” and “quick edit” are not applicable to field groups but they have a delete action and an regular edit action.

  • Hi @rkeefer

    Here’s how you would do this based on the code you’ve provided

    
    elseif( get_row_layout() == 'quotes_slider' ):
    
    	$heading = get_sub_field('heading');											
    	$quotes = get_sub_field('quotes');
    	?>
    	<div class="ctaContent ctaContent1 ctaTestimonials clearfix">
    		<h3><?php echo $heading; ?></h3>
    		<div class="flexslider" id="testimonialsSlider1">											
    			<ul class="slides">
    				<?php foreach($quotes as $quote): ?>
    					<li>
    						<?php echo $quote['subfieldname']; ?>
    					</li>
    				<?php endforeach; ?>
    			</ul>												
    		</div><!-- #testimonialsSlider1 -->											
    	</div>
    <?php endif; ?>
    

    Good luck!

  • EDIT: Actually what ended up happening was as I was changing some varaibles I misspelled one of them.

    After looking over everything it seems that my get_posts is not returning anything in the array and is NULL.

    <?php
    $teamLeaders = get_posts(array(
                    'post_type' => 'mro_volunteer',
                    'meta_query' => array(
                      array(
                        'key' => 'assigned_project', // name of custom field
                        'value' => '"' . get_the_ID() . '"', // matches exaclty
                        'compare' => 'LIKE'
                      )
                    )
                  ));
    ?>

    This is the correct post type and correct key, I checked the volunteers that are published and they all have the project in question assigned to them through the relationship field. I’m not sure why it can’t query them. It’s limited to only one if that makes any difference.

  • Hi @jonathan I really appreciate the input. You solution/work around makes sense but I am a little concerned because I feel like I may be putting a bandaid on the submit to repeater since it’s not truly supported.

    I may handle this a little different than I originally planned since there are going to be 1000s of posts each with up to 20 repeater rows per-post. I think I may create a post type to store the actual location data (what I am calling sightings). I can then create a relationship between the listings post type and the sightings post type. I should be able to then query everything as needed. Thanks for the help.

  • You can’t include ACF field in csv import, you have to add this functionality in plugin.

    You don’t need field id generated by ACF to use meta values. Just call WP_User_Query with a meta_query.

  • Hi Greenhoe,

    I don’t think you can easily update the taxonomy parameter of your field once the edit screen has been rendered. It would require an AJAX call and recreating the entire field dynamically..

    May I suggest a different solution that’s maybe a bit easier and doable.
    If you use a relationship field instead there’s a built in filter capability for taxonomies. You can set the field to only allow for 1 value so that it’ll work pretty much the same as the post_object field.

    Then if you really want you should be able to create some custom Javascript for the extra functionality. Look for a change in the taxonomy dropdown and change the taxonomy filter dropdown in the relationship field accordingly. It should trigger the filtering automatically. If you also want to make sure the client can’t change the filter themselves you could just add a tiny CSS snippet to hide the taxonomy filter from them.

    What do you think?

  • Hi @bruno-martins

    I am not sure what you mean by “It does not work” is the Repeater field not saving values? If this is the case, it may be related to the field_name length.

    ACF uses the field’s name to save a value into the database. When saving sub fields, the ‘save name’ is generated by the ancestors names + the row index and can become quite long. It is possible that the length of this ‘save name’ can become too long for the wp_options table, and WP will not be able to save the value at all.

    You can solve this by reducing the field name length.

    If the issue is to do with the field not saving, you can make the following changes to the php.ini file:

    max_input_vars = 3000
    suhosin.get.max_vars = 3000
    suhosin.post.max_vars = 3000
    suhosin.request.max_vars = 3000
  • Hi @maliakmal

    The Google Map Field relies entirely on the google map API and thus it is recommended to consult the Google team for more APIs and for further tutorials.

    It is however important to note that not all browsers support geolocation, it is a device-specific API; some browser/devices support it, while others do not (or cannot).

    You can use the W3C navigator.geolocation property to get the location using the following code:

    var initialLocation;
    var siberia = new google.maps.LatLng(60, 105);
    var newyork = new google.maps.LatLng(40.69847032728747, -73.9514422416687);
    var browserSupportFlag =  new Boolean();
    
    function initialize() {
      var myOptions = {
        zoom: 6,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      };
      var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
    
      // Try W3C Geolocation (Preferred)
      if(navigator.geolocation) {
        browserSupportFlag = true;
        navigator.geolocation.getCurrentPosition(function(position) {
          initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
          map.setCenter(initialLocation);
        }, function() {
          handleNoGeolocation(browserSupportFlag);
        });
      }
      // Browser doesn't support Geolocation
      else {
        browserSupportFlag = false;
        handleNoGeolocation(browserSupportFlag);
      }
    
      function handleNoGeolocation(errorFlag) {
        if (errorFlag == true) {
          alert("Geolocation service failed.");
          initialLocation = newyork;
        } else {
          alert("Your browser doesn't support geolocation. We've placed you in Siberia.");
          initialLocation = siberia;
        }
        map.setCenter(initialLocation);
      }
    }
  • Hi @jimrapt

    We have not had similar reports of this, therefore this is less likely to be a bug.

    It seems something might be interfering with the database queries and thus the wrong results, you need to investigate whether this issue could be stemming from your theme by deactivating it and switching to one of the stock Wp themes.

    If this fails to solve the issue you might need to do a fresh install of WordPress.

  • If this is a bug it would be a WP bug. But looking at your query there are few things that stand out. One is that you have a meta_query that I don’t think you need and the second is that in that meta_query you are telling that the meta field is a date and I’m pretty sure that WP expects this to be in YYYY-MM-DD format, so your dates may be being read wrong. The last thing is that you are using orderby => meta_value_number.

    Try this for your query:

    
    $args = array(
        'post_type' => 'project',
        'meta_key' => 'project_date',
        'orderby'=> 'meta_value',
        'order' => 'DESC',
        'paged' => $paged
    );
    $wp_query = new WP_Query($args);
    get_template_part('templates/loop', 'project');
    
  • Hi guys

    Just want to let you know I have added in some new filters for the user field and will be included in the next version of ACF PRO:

    result
    – used to modify the text which is displayed for each user result

    
    $result = apply_filters("acf/fields/user/result", $result, $user, $field, $post_id);
    $result = apply_filters("acf/fields/user/result/name={$field['_name']}", $result, $user, $field, $post_id);
    $result = apply_filters("acf/fields/user/result/key={$field['key']}", $result, $user, $field, $post_id);
    

    search_columns
    – used to modify the columns which are searched

    
    $columns = apply_filters("acf/fields/user/search_columns", $columns, $search, $WP_User_Query, $field);
    $columns = apply_filters("acf/fields/user/search_columns/name={$field['_name']}", $columns, $search, $WP_User_Query, $field);
    $columns = apply_filters("acf/fields/user/search_columns/key={$field['key']}", $columns, $search, $WP_User_Query, $field);
    

    Hopefully these are self explanatory. I’ll add documentation soon

    Thanks
    E

  • The relationship field => author is stored in the database as a post ID. (if it is a post object field, it’s an array of post IDs if it’s a relationship.)

    On top of that, if I understand you correctly, you are trying to order your publication posts by the title of your author posts. So you’re trying to order the posts by the title of other posts. This is not going to be possible using just a WP query.

    You’re going to need to get all the authors in the order you want them. Then you’re going to need to get all the publications and then you’re going to have to figure out how to order the publications by the authors. While possible, that’s complicated just to think about.

    You could create an acf/save_post action and in that action you could get the selected author, get the authors name and store the name in another custom field using update_post_meta(). I would hide this field by adding an _ to the beginning like _author_name The you could sort your publications by this hidden custom field. This would be a lot less work then trying to sort post by the titles of related posts.

  • First sn explanation of why I say to use pre_get_posts and to put the in functions.php.

    If you have a custom post type, and you create a template for the archive of that post type, then you do not need to do a query to get the posts of the post type, WP does that already.

    Example: I create a post type called “product” and I create 2 template files “single-product.php” and “archive-product.php”. WordPress automatically does the queries needed to get the product posts when these templates are use and these templates will be used whenever product posts are being requested. WP will run whether you want it to run or not so you may as well use it. The pre_get_posts hook allows you to alter what WP gets in this default query.

    Doing this any other way doubles the amount of queries and work that WP needs to do to load a page.

    If you still want to do a query then you can add the meta query I gave you to the query you are doing.

    
    $args = array(
        'post_type' => 'my-post-type',
        'posts_per_page' => 6,
        'meta_query' => array(
            array(
                'key' => 'my_field',
                'value' => '1'
            ),
    );
    $query = new WP_Query($args);
    
  • This – from the ACF docs – is the kind of thing I’m trying to do, but this code isn’t working:

    $posts = get_posts(array(
        'meta_query' => array(
            array(
                'key' => 'field_name', // name of custom field
                'value' => '"red"', // matches exaclty "red", not just red. This prevents a match for "acquired"
                'compare' => 'LIKE'
            )
        )
    ));
    
    if( $posts )
    {
        //...
    }
  • Your initial assumption is correct, I need it to filter out the posts that are returned so needs to be in the query. Not for the main loop, but for a Custom Post Type loop.

    But it’s a checkbox, so it can have one or multiple items. Though I am checking for just one item per query (this will be used a number of times depending on page) so it might still work, I’ll give it a go.

    Cheers.

  • This question sounds like it’s related directly to this other question http://support.advancedcustomfields.com/forums/topic/wp-loop-via-checkbox-value/

    The pagination function will work without doing a new query for your custom post type. I wouldn’t follow that post.

    The correct way to do this is to create a template for your custom post type archive following the WP template hierarchy and then do a pre_get_posts action like I showed in that question.

    Previous and next post link function are documented here https://codex.wordpress.org/Function_Reference/previous_posts_link and here https://codex.wordpress.org/Template_Tags/next_posts_link

  • You have a checkbox field, by this I’m assuming that this is a True/False field because you say "if it is true then that item is included in the loop"

    When you say that you want it included in the loop, here I’m assuming that you mean included in the posts that are returned by WP_Query, either the main query or a custom query.

    Is it a custom query or the main WP query that you are looking to alter to only include posts that are marked as true? My answer below is assuming that you mean the main WP query because you did not mention a custom query and "if it is true then that item is included in the loop"

    Let me know if I have any of this wrong.

    If my assumptions are correct then you need to add a pre_get_posts filter in WP.

    To your functions.php file add something like:

    
    // change "my_post_type" to the name of your post type
    // change "my_field" to the name of your ACF field
    function my_post_type_pre_get_posts($query) {
      if (is_admin() || !$query->is_main_query()) {
        return;
      }
      if ($query->query_vars['post_type'] == 'my_post_type') {
        $meta_query = array(
          array(
            'key' => 'my_field',
            'value' => '1' // this is the value that ACF saves
                           // for a true value in a true/false field
          )
        );
        $query->set('meta_query', $meta_query);
      }
    }
    add_action('pre_get_posts', 'my_post_type_pre_get_posts');
    
  • I don’t think you’ll find a specific tutorial that will cover everything you need, but yes, this is possible.

    Here is a quick overview of what needs to be done.

    1. You need to create JavaScript that makes use that:
      1. Makes use of timeouts to check for changes on a regular bases. You can find plenty of information on timeouts by doing a google search.
      2. Is attached to the onclick of a link or button
    2. When the timeout fires you send an AJAX request, you’ll need to send the post ID so that your server side script knows what post to get the values for. The best information on AJAX in WP can be found here: https://codex.wordpress.org/AJAX_in_Plugins
    3. You’re server side script then gets the values from the ACF fields and sends them back. I would send them as a JSON object
    4. You’re AJAX Callback function parses the returned value and updates the content on the page.
  • Thanks
    So far I have been using this format:
    field_{field_group_name}_{field_name}

    Everything has been working fine as long as I use a unique group name and label name. Which you need to do anyways.

    I think there should be an option to leave it blank and it will use this format.

    I did have issues with older versions of ACF with the field id, but with 4.4.1 we don’t have any issues now.

  • I must have marked this at one time because I was interested in the topic and I got and email about a reply.

    Don’t know if this will help you at all but you do not need to use the field keys that ACF generates, but you do need some type of field keys. Using field keys can also be necessary in some filters and actions.

    This is the way that ACF keeps track of everything in the database and gives everything a unique value. It is very easy to create 2 field groups that both have the same field name, but the keys need to be unique.

    I build plugins that use ACF all the time and put the code for generating field keys into PHP all the time, then I alter the field keys. From my experience you can make them anything as long as you follow a few rules.

    1) they all begin with “field_”
    2) they are 19 characters long (that give you 13 characters), I’m not too sure about this but better safe than sorry.
    3) the part after “field_” has only numbers and letters. I’ve run into issues in the past where I included a second underscore.

    What I do is I use a unique prefix, lets say I decide to use “abcd” for a particular plugin the I create field keys like

    field_abcd000000001
    field_abcd000000002
    field_abcd000000003
    etc.

  • The last rule

    OR

    Post Type is not equal to Event

    That basically overrides all the other rules. If the post type is not event then it will show the group. Since this is for pages, you don’t need that last rule.

    Also, this rule

    OR
    Page Type is equal to Top Level Page no parent

    should be combined with the other rules as an AND unless you want it to appear on all top level pages regardless of what template they use.

  • Hi @madivad,

    I must say your implementation is quite complex but if you are not willing to use a plugin to simplify things, another option would be to use the acf/input/admin_enqueue_scripts action to register the custom styles.

    This action is limited to pages where field inputs are generated.

    You can have a look through the following link: http://www.advancedcustomfields.com/resources/acfinputadmin_enqueue_scripts/

  • If you mean the standard WP post title field. What you need to do is create another field for people to enter the title and then convert that into a title in an acf_pre_save_post filter. There is an example of doing this in this question http://support.advancedcustomfields.com/forums/topic/radio-field-conditional-in-afc_form/ and you can read more about it here http://www.advancedcustomfields.com/resources/acf-pre_save_post/

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