Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • Hi John

    Thank you so much for your time and effort.

    I’m getting a time-out. I think it is pulling to many posts.
    Thought about adding a query (the page is a custom post type), but now i’m getting an error message.

    Warning: htmlspecialchars() expects parameter 1 to be string, object given

    function my_acf_load_value($value, $post_id, $field) {
    $query = new WP_Query( array( 'post_type' => 'artikler', 'posts_per_page' => 1, ) );
    return $query;
    
      if ($query->have_rows('artikel', $post_id)) {
        while ($query->have_rows('artikel', $post_id)) {
          $post_object_id = get_sub_field('artikel_navn', false);
          $values = get_field('tekst', $post_object_id);
        }
        $value = implode(', ', $values);
      }
      return $value;
    }
    add_filter('acf/update_value/name=meta_beskrivelse', 'my_acf_load_value', 10, 3);
  • To do this in real time you need js…

    
    <input id="remember" name="remember" type="checkbox" onclick="validate()" />
    
    <script type="text/javascript">
        function validate() {
            if (document.getElementById('remember').checked) {
                alert("Checked"); //Here you can print your date
            } else {
                alert("Unchecked");
            }
        }
    </script>
    
  • Hey John,

    We’re using Advanced Custom Fields 4.4.11.

    However, entering the code you supplied worked like a charm:

    <?php 
    $queried_object = get_queried_object();
    $taxonomy = $queried_object->taxonomy;
    $term_id = $queried_object->term_id;
    // the_field() echos the value and you do not need to include your own echo statement
    the_field('game_publisher', $taxonomy.'_'.$term_id);
    ?>

    Thank you!

  • Are you using ACF 4 or 5?

    In either case you need to supply the correct post ID value. In ACF for this is "{$taonomy}_{$term_id}". In ACF 5 you can use the same value or you can use "term_{$term_id}"

    In a tax archive template you can get the term ID like this

    
    $queried_object = get_queried_object();
    $taxonomy = $queried_object->taxonomy;
    $term_id = $queried_object->term_id;
    

    To get the field you should either use

    
    // the_field() echos the value and you do not need to include your own echo statement
    the_field('game_publisher', $taxonomy.'_'.$term_id);
    

    or

    
    echo get_field('game_publisher', $taxonomy.'_'.$term_id);
    

    for more information see https://www.advancedcustomfields.com/resources/get_field/ Get a value from different objects

  • I just fixed it with acf/fields/taxonomy/wp_list_categories. I had to look up all the numerical value of the terms I want excluded, but it works

    function my_taxonomy_query( $args, $field) {
      
     $args['exclude'] = array(91,96,2,26,33,15,64,44,62,11,95,77,66,71,10,92,67);
    
        return $args;
        
    }
    
    add_filter('acf/fields/taxonomy/wp_list_categories', 'my_taxonomy_query', 10, 2);

    The acf/fields/taxonomy/query filter didn’t work for me at all for some reason, couldn’t even get the example code to work.

  • Actually, yes. You can use the acf/fields/taxonomy/query filter https://www.advancedcustomfields.com/resources/acf-fields-taxonomy-query/ and adjust the arguments for get_terms() https://developer.wordpress.org/reference/classes/wp_term_query/__construct/ using the “exclude” argument.

  • Thank you! It works perfectly. I do find the update_field() documentation for repeater fields confusing…

    // save a repeater field value
    $field_key = "field_12345678";
    $value = array(
        array(
            "sub_field_1"	=> "Foo",
            "sub_field_2"	=> "Bar"
        )
    );
    update_field( $field_key, $value, $post_id );
  • This is not something that ACF can control. When a field group is first added the default, original location is decided by when WP invokes the hook for displaying custom meta boxes.

    After this point, any user can drag these sortable meta boxes to any order they wish and WP will remember that order. In the _usermeta table there is an entry for each user and each post type. For example for posts the meta_key is meta-box-order_post the key is created like "meta-box-order_{$post_type}". This db entry stores a serialized array that records the order that the sortables were in the last time that the user saved a post.

    In order to take control and force these to a specific configuration for your post you would need to get this entry and update it every time the user logs in, or saves a post, or at other times to ensure that they are in the order that you want them.

    Check out this for some possible solutions https://wordpress.stackexchange.com/questions/124330/metabox-layout-for-all-users

  • Look at https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters and look for ‘orderby’ with multiple ‘meta_key’s and also here https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query/

    This should probably be done with a pre_get_posts filter to alter the main query. This is an example using what you’ve posted to give an example.

    
    $args = array(
      'numberposts' => -1,
      'post_type' => 'locations',
      'meta_query' => array(
        'state_clause' => array(
          'key' => 'state',
          'compare' => 'EXISTS',
        ),
        'city_clause' => array(
          'key' => 'city',
          'compare' => 'EXISTS',
        ),
      ),
      'orderby' => array(
        'state_clause' => 'ASC',
        'city_clause' => 'ASC',
        'title' => 'ASC'
      )
    );
    $the_query = new WP_Query($args);
    

    The above will order all of the posts so that they end up being grouped together by state and then city. The next step is that as you’re looping through the posts you need to look at what the state/city of the post is and compare it to the previous post. This can be a little confusing because of the circular logic of possibly outputting closing tag for elements before outputting the matching opening tags for those elements.

    
    if ($the_query->have_posts()) {
      // variables to hold values from previous post
      $last_state = '';
      $last_city = '';
      
      while ($the_query->have_posts()) {
        // get state and compare it to the previous post
        $this_state = get_field('state');
        if ($this_state != $last_state) {
          // the state has changed
          if ($last_state != '') {
            // close the post UL, city DIV, and state DIV that we'll open next
            // this will be skipped if this is the first post
            // because $last_state will be empty
            echo '</ul></div><!-- .city --></div><!-- .state -->';
          }
          echo '<div class="state"><h2>'.$this_state.'</h2>';
          // clear $last_city
          $last_city = '';
          // set $last_state to $this_state
          $last_state = $this_state;
        } // end if new state
        // get the city and compare to previous post
        $this_city = get_field('city');
        if ($this_city != $last_city) {
          // the city has changed
          if ($last_city != '') {
            // close the post UL, city DIV we'll open next
            // this will be skipped if this is the first post for city
            // because $last_city will be empty
            echo '</ul></div><!-- .city -->';
          }
          echo '<div class="city"><h3>'.$this_city.'</h3><ul>';
          // set $last_city to $this_city
          $last_city = $this_city;
        } // end if new city
        ?>
          <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
        <?php 
      } // end while have posts
      // we need to close the last set of elements that were opened
      echo '</ul></div><!-- .city --></div><!-- .state -->';
    } // end if have_posts
    
  • Where are the posts for the archive queried? Is this code being used on archive-locations.php? What you need to do is to alter the query that is getting all of the locations posts to sort both of these fields, but how you go about altering the original query depends on where it’s being done.

  • @markbloomfield

    Absolutely, my mistake to skip the #6 as I think it has to be done the other step, my confusion,sorry.But Why we have two forms in one page. The first form has title field and content field from this one (‘post_title’=> true,’post_content’=> true,). And the second form is the form from the group field. When I go to this form page to create a new post, I have to fill up the information into both forms. How can I separate them?

    I added a post id at the end of the url. This brings an edit screen to the first form. Hmmm, as I told you that I use Social Article. Posts that users create are listed in the tab in user profile. There there’s an edit button to every post. When users click on that edit button, how to bring users to that edit screen? How can I edit the path? Please see the picture. https://www.dropbox.com/s/w9dl0z8yl1qt9cg/123.jpg?dl=0

    And next to Publish button, can I have Save to Draft button, totally two buttons.

    Thanks.

  • I know was a feature request and was just pointing out a way this can be done with the newest version of ACF. If you really think this is something that should be added then you should submit a request here https://support.advancedcustomfields.com/new-ticket/

  • Thanks @topy

    You had missed out step 6 from my tutorial completely – IE the code to actually show the form, was not placed into your Form.php page template.

    I did this, and the form showed immediately 🙂

    Screenshot of how the code should look: http://d.pr/i/QF9CP9
    Screenshot of your site with the form: http://d.pr/i/ZBtAym

    So all you need to do is open your Form.php and put this code wherever you want the form to appear:

    
    <?php
    	$formoptions = array(
    		'post_title'      => true,
    		'post_content'    => true,
    		'post_id'         => $new_post,
    		'new_post'        => array(
    			'post_type'       => 'post', // change this to the post type you need
    			'post_status'     => 'publish' // do you want the post to be published immediately? otherwise change this to 'draft'
    		),
    		'field_groups'    => array(9), // change this number to the ID of your field group
    		'submit_value'    => 'Publish',
    		'return'          => get_permalink(24), // change this ID to the page you want to send the user back to when they've submitted the form - perhaps a thank you page
    		'uploader'        => 'wp'
    	);
    	acf_form($formoptions);
    ?>
    

    Hope this helps 🙂

  • I’m sorry for getting back to this late. Thank for you pointing me to the right direction, it quickly solved the issue.

  • @topy the tutorial I gave you, is what I did on a site of my own in the last 2 weeks, so it definitely works.

    But i’d like to help check your code + setup on my end. If you don’t have a server to upload this to yet, then you can:

    1) zip up the whole WP folder for the site and upload it somewhere and give me the link here

    2) if you’re using WAMP, you should be able to browse to http://localhost/phpmyadmin to gain access to your databases so you can export them. Export the SQL file for your site and zip this up too and reply here with a link to both files. If you can’t get this right, then you can also find + install a plugin that will create a backup of your database and let you download it.

    Will wait for your reply here with those files 🙂

  • You’re using get_field() where you should probably be using the_field()

    
    <div id="affiliatebutton"> <a href="<?php 
      // use the_field() here
      the_field ('affiliate_button_link_url') ; ?>" target="_blank"><?php 
      the_field('affiliate_button_label');?></a></div
    
  • A similar question is asked here https://support.advancedcustomfields.com/forums/topic/repeater-field-in-functions-php-2/

    You may need to include the $post_id when calling have_rows()

  • Calling get_fields() can reduce the number of queries done. This does one DB query to get all meta values and WP caches the results of the query.

    Once you use get_fields() it does not matter after this if you use get_field() to get each field value because this will not cause any more queries to be done.

  • You need to do some additional checking

    
    add_action( 'pre_get_posts', 'themeprefix_pre_get_posts' );
    function themeprefix_pre_get_posts( $query ) {
    	
    	if ( is_admin() || !$query->is_main_query() )
    		return $query;
    	
    	// Show only active job openings
    	if ( is_post_type_archive ( 'job' ) ) {
    		$query->set( 'meta_key',   'status' );
    		$query->set( 'meta_value', 'active' );
    	}
    	
    	return $query;
    }
    

    there may also be some additional checks you need to do.

  • If you are seeing a different number of queries being done when using get_field() as apposed to get_fields(), there are some things you can to.

    The first thing is to call get_post_meta($post->ID), this will cause all of the meta values for a post to be loaded into the WP cache and then any additional calls will not create additional queries.

    calling get_fields() will cause the same thing to happen as the first option.

    Once this is done you don’t really need to use the array that’s returned, you can just use get_field('field_name') after that and these will get values from the cache and not do an additional query.

    I’m not really sure why you’d be seeing a difference in the number of queries unless you’re getting values from another post, not the current post in “The Loop”. Usually, I’ve found that when setting up a post WP automatically gets all the post meta values automatically.

  • @markbloomfield

    I am new to WordPress. This is my first time to create a website with WP. And I haven’t decided on any web hosting yet. I don’t know about staging/test server you are referring to, and also to back up the .sql, I don’t know how to do either.

    To make sure there’s no any conflict, I even have created a new database and installed a new WordPress file, new theme file is also replaced. Everything is new. Then I install only ACF Pro and repeat the instructions, the result is still the same. I think there must be something wrong with the tutorial you give me?

  • Yes, it works. This show my post id, for example:

    id="entry-3453"

  • I’ve managed to get it working by retrieving fields values from the POST request.

    function show_update_postdata( $value, $post_id, $field ) {
    
            // Get values from POST
            $date = strtotime($_POST['acf']['field_595cf97c444c0']);
            $band = get_the_title($_POST['acf']['field_595cfa314cf4b']);
            $country = $_POST['acf']['field_595cf99f444c1'];
            $city = $_POST['acf']['field_595cf9f1444c2'];
    
            // Custom post title
            $formatted_date = date_i18n('F jS, Y', $date);
            $title = $band . ' @ ' . $city . ', ' . $country . ' - ' . $formatted_date;
            $slug = sanitize_title( $title );
            $postdata = array(
                 'ID'          => $post_id,
                 'post_title'  => $title,
                 'post_type'   => 'show',
                 'post_name'   => $slug
            );
    
            wp_update_post( $postdata );
            return $value;
    
    }
    add_filter('acf/update_value/name=date', 'show_update_postdata', 10, 3);
    add_filter('acf/update_value/name=band', 'show_update_postdata', 10, 3);
    add_filter('acf/update_value/name=city', 'show_update_postdata', 10, 3);
    add_filter('acf/update_value/name=country', 'show_update_postdata', 10, 3);
  • and is $post->ID echo’ing out the post ID correctly elsewhere? IE in the id="entry-<?php echo $post->ID; ?>" part?

  • So I’ve managed to store my select field’s value, by passing it to a hidden input field, which works fine. But now I’m facing some trouble with the repeater field.

    ACF generates a repeater’s subfield $field[‘name’] and $field[‘ID’], by replacing [acfcloneindex] by an $i integer value, through the use of javascript–see this post for reference.
    I haven’t found a way to get around the [acfcloneindex] riddle yet, but I’m wondering how ACF stores its own select fields values.

    I’m generating the select code of my field using the same structure as ACF, but ACF won’t store the value upon saving the post:

    echo '<select id="' . esc_attr($field['id']) . '" name="' . esc_attr($field['name']) .'" data-ui="0" data-ajax="0" data-multiple="0" data-placeholder="Select" data-allow_null="0">';
    $output .= '<option value="0"></option>';
    foreach($options as $option){
    ...
    }
    echo $output . '</select>';

    So the question is, what am I missing? How can I store my select field’s value?

    I figure there has to be a better way than by using hidden inputs, right?

Viewing 25 results - 11,001 through 11,025 (of 21,318 total)