Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • Oh Sorry my mistake, can you replace it with :

    '"85"'

  • I think compare would be LIKE and the value not in the array but ‘”85″‘ or 'value' => '"' . get_the_ID() . '"'

  • Oh so you Authors is a repeater and in that you have a multiple select post object that is People? If so try this:

    $images_query = new WP_Query([
        'posts_per_page' => -1,
        'post_type' => 'images',
        'meta_query' => [
            [
                'key' => 'authors_%_people',
                'compare' => 'LIKE'
                'value' => '"'.85.'"',
            ],
        ],
    ]);
  • I have now read section 4 of that article, but I don’t really understand it because I’m not too hot on mySQL. But either way, I’ve added the following to my functions file :

    function my_posts_where( $where ) {
        global $wpdb;
        $where = str_replace(
                  "meta_key = 'authors_", 
                  "meta_key LIKE 'authors_",
                  $wpdb->remove_placeholder_escape($where)
        );
        return $where;
    }
     
    add_filter('posts_where', 'my_posts_where');

    and I’m trying to query like this …

    $images_query = new WP_Query([
        'posts_per_page' => -1,
        'post_type' => 'images',
        'meta_query' => [
            [
                'key' => 'authors_%_people',
                'compare' => '='
                'value' => ['85'],
            ],
        ],
    ]);

    Any ideas why this wouldn’t be working? Could it be because I allow multiple values in the people post_object field?

    What do you mean by “create a custom field for this query”?

  • Have a read of this post, Section 4 to be precise: https://www.advancedcustomfields.com/resources/query-posts-custom-fields/

    In order to use a % wildcard you need to create a custom field for this query.

    See if that works for you.

  • Have you added this code to functions.php ?

    function my_posts_where( $where ) {
        global $wpdb;
        $where = str_replace(
                  "meta_key = 'authors_", 
                  "meta_key LIKE 'authors_",
                  $wpdb->remove_placeholder_escape($where)
        );
        return $where;
    }
     
    add_filter('posts_where', 'my_posts_where');
  • My fields are as follows: authors is a group field and within that I have a subfield of people (amongst other subfields). People is a multiple post_object select field.

    I have the impression from this thread that it is possible to query subfields in this way…

    $images_query = new WP_Query([
        'posts_per_page' => -1,
        'post_type' => 'images',
        'meta_query' => [
            [
                'key' => 'authors_%_people',
                'value' => ['85'],
                'compare' => 'IN'
            ],
        ],
    ]);

    It is not working, please could you advise me.

  • Please could you help me figure out how to run a WP_Query with meta_query such that posts-types are filtered by a subfield within a group field.

    I have a custom post type of image and an acf group field of authors with a subfield of people. People is a multi-select post_object field. What would I need to do to get images only where people contains a certain id?

    I’m trying something like this based on John Huebner’s comment above.

    $images_query = new WP_Query([
        'posts_per_page' => -1,
        'post_type' => 'images',
        'meta_query' => [
            [
                'key' => 'authors_%_people',
                'value' => ['85'],
                'compare' => 'IN'
            ],
        ],
    ]);

    I’ve clearly got something wrong, Nothing is working. Please help.

  • Yes this is still wanted. Recently had another large batch of websites lose their license keys. The custom code I previously used to reapply license keys stopped working. I assume something changed with the way ACF Pro activate license keys. I was able to get working by updating the custom code to match the code within ACF Pro itself.

    // Check if ACF is running
    if ( is_plugin_active( 'advanced-custom-fields-pro/acf.php' ) ) {
    
      // Loads ACF plugin
      include_once( ABSPATH . 'wp-content/plugins/advanced-custom-fields-pro/acf.php');
    
      // connect
      $post = array(
        'acf_license'	=> "ACF_PRO_KEY",
        'acf_version'	=> acf_get_setting('version'),
        'wp_name'			=> get_bloginfo('name'),
        'wp_url'			=> home_url(),
        'wp_version'	=> get_bloginfo('version'),
        'wp_language'	=> get_bloginfo('language'),
        'wp_timezone'	=> get_option('timezone_string'),
      );
    
      // connect
      $response = acf_updates()->request('v2/plugins/activate?p=pro', $post);
    
      // ensure response is expected JSON array (not string)
      if( is_string($response) ) {
        $response = new WP_Error( 'server_error', esc_html($response) );
      }
    
      // success
      if( $response['status'] == 1 ) {
        acf_pro_update_license( $response['license'] ); // update license
      }
      echo $response['message']; // show message
    
    }

    Also wrote some code to make this automatically update after using a WP-CLI search-replace command. That’s typically where I’m seeing the license keys drop. https://anchor.host/2017/05/16/preloading-advanced-custom-fields-pro-license-key/

  • PS. as per my question above in this tread. I was expecting the output of the met_query to be a full user_object but the key was just an ID. AFC builds the user object from the stored ID when get_field is called. I bet your issue is similar.

  • Two things you can try:

    1. value does accept an arra so that may help matching on a post_object -> ‘value’ => array(‘auth1′,’auth2’),
    2. Ensure the key author matches the query_var type. e.g. if author is name you may need to convert it to ID etc.

    Basically check what exact data the AFC field is saving… It’s not always what you expect because the AFC output is an abstracted version of the data and not the raw values which meta_query uses for matching. Look at author key->values in the DB or var_dump using get_post_meta not get_field.

  • I have a problem with trying to implement something similar…
    Here is my setup…

    Custom post type : ‘images’
    Custom post type : ‘authors’

    I have a multiple select post_object field on the images edit screen where you can select multiple authors. I have set this to output a post object in the acf edit field group page because I use various fields from the authors on the image display.

    Now I have a filtering option in the images archive and want to be able to query images of a particular author.

    $images_query = new WP_Query([
        'posts_per_page' => -1,
        'post_type' => 'images',
        'meta_query' => array(
            array(
                'key' => 'author',
                'value' => get_query_var('author'),
                'compare' => 'LIKE'
            ),
        )
    ]);

    I have got everything working without the meta_query so it’s not a loop problem, but nothing is showing up from my output loop when I add the meta_query.

    Does anyone know if the problem is due to my acf output being a post object rather than a post id? Please advise.

  • I fixed it. Fixes same problem with Table of content.

    I just add the fields i want to be parsed by the plugins to wordpress’ the_content() in my template.

    <?php 			
    add_filter('the_content','prepend_this');
    function prepend_this($content)
    {
        $content = get_field("some_field");
        return $content;
    }
    ?>
    <?php the_content(); ?>

    my site uses only ACF fields for content, so the_content() is always empty. Your results may vary.

    If something’s not clear, ask away.

  • Hi,

    I tried both solutions, Rob’s one works, but John’s one doesn’t.
    I thought it was a problem in rendering/loading the google_map field/value,
    so I’ve tried update_value on a basic ACF text field, passing its $value to another ACF field, but nothing happens.
    I’ve tried overriding the returned $value as in docs usage example and it fires only when I save the post (publish or update – so I don’t get the difference with save_post action).
    As far as it regards:

    do something else to the $post object via the $post_id

    neither ACF update_field nor WP update_post_meta seems to work.

    So, hooking WP save_post does the job, but I wonder if there’s a way to dynamically update ACF fields while updating other ACF field value.
    Cheers

  • Something is causing the AJAX request for the results to fail. There is most likely a JavaScript error or a PHP error during the AJAX request. Look in console and see if there are any JS errors and clear those up and turn on WP_DEBUG and logging to see if there are any errors happening during the AJAX request https://codex.wordpress.org/WP_DEBUG

  • While @gummi’s solution will get you there, I think that it’s always better to code this, especially when dealing with new values. As a developer and programmer it’s not a good programming practice to assume that a value will always be present.

    
    $value = get_field('field_name');
    if (!$value) {
      $value = 'some default value';
    }
    

    Yes, this does mean a little more code, but it’s a lot less work than updating every post on a site to have the default value.

    If you have thousands of posts on a large site there’s a good chance that the loop and update will time out the site. If you are going to do the update method I would suggest altering the query to only get posts where no value exists as it will get less posts and if it times out you can reload the page until it completes.

    
        // 1. get all the posts first
        $allPosts = new WP_Query([
            'post_type' => 'post', // assuming your field is added on 'post' post type
            'posts_per_page' => -1,
            'meta_query' => array(
                'key' => 'your field name here',
                'compare' => NOT EXISTS'
            )
        ]);
    
    
  • @extrasmall Thanks for the above code! I got as far as understanding why the str_replace wasn’t working, but didn’t know where the {……..} in the query was coming from.

  • Hi,
    I had the same problem.
    I made a loop on CPT and in each one I need a post-objet.

    Here is what i made

    <table>
    <tr>
    <td>Nom/Prénom</td><td>Numéro de téléphone</td><td >email</td><td>Commission</td>
    </tr>    
            
         
    <?php	while($author_posts_contacts->have_posts()) : $author_posts_contacts->the_post();?>
        <tr>
        	<td> <?php $id_post_origine=get_the_ID();?>//Register the "parent" post id
            <strong><?php the_field('titre_du_post'); ?> <?php the_field('nom_correspondant_festo'); ?></a></strong></br>
    		<?php $post_object = get_field('structure'); if( $post_object ): 	$post = $post_object; setup_postdata( $post );	?>//Call the post object Inside and work with
    (<?php the_title(); ?>)
    <?php $post = $id_post_origine; setup_postdata( $post ); ////Call back the "parent" post datas
    
    endif; ?>
            </td>
            <td><?php the_field('numero_de_telephone_correspondant_festo'); ?></td>
            <td><?php the_field('email_correspondant_festo'); ?></td>
            <td><?php $mots_cles = get_field('commission_correspondant_festo');
    		foreach ($mots_cles as $mot_cle):
    		$id_du_mot_cle = get_term( $mot_cle);
    		echo $id_du_mot_cle->name.'</br>';
    		endforeach;?>
            
    		
    </td></tr>
               
        <?php           
        endwhile;?></table>

    I hope this helps.

  • Storing the CPTs metadata in custom database tables might be a good solution to greatly improve the performance of database queries. The problem and the solution are explained here

  • Hi,

    In your case, you are only updating 1 field, it’d be better to just target that field in the loop. It’s just safer to not messed up other saved value.

    try something like this:

    
    <?php
    
    function temp_update_value() {
        // 1. get all the posts first
        $allPosts = new WP_Query([
            'post_type' => 'post', // assuming your field is added on 'post' post type
            'posts_per_page' => -1
        ]);
    
        // 2. loop through each posts, and update the acf value
        while ($allPosts->have_posts()): $allPosts->the_post();
            // 3. check if the value is already set, if it does, go to next post
            if (get_field('key_1234567890') !== null) {
                continue;
            }
    
            // 3. update the acf value by the field key
            update_field('key_1234567890', 'your value');
        endwhile; wp_reset_query();
    }
    
    // 4. just in case, use acf/init to make sure acf is finish initilizing
    add_action('acf/init', 'temp_update_value');
    

    put this inside your functions.php file, and refresh any page once to kick it off. After than remember to remove or comment out from you functions.php so it doesn’t get run every time.

    Cheers.

  • I have a custom field with location rule on custom post type and i want to check this custom field value(Radio button field) on Taxonomy terms page .How can do that
    is premium ? Yes No
    this is a field on custom posts ‘listing’ and i want to check this field value on
    ‘taxonomy-listing’ Page .
    I don’t want them to use inside WP Query , But want to run various WP Query according to value of ‘is premium?’

    Pls Help

  • This is not something that exists, or ever has as far as I can remember. You can submit a support ticket to request the feature, but I can’t say if it’s possible. Knowing what I know, I don’t think that this would be an easy feature to add to ACF (but then I’m not the developer) https://support.advancedcustomfields.com/new-ticket/

  • I’m not the developer, but I can try to answer your questions

    1) performance will depend on the queries you use. With relationship field I would look into 2 way relationship. There is code on this site that will help as well as plugins available. There are a lot of other things that can be looked at but far too many to list them all here.

    2) the Pro version of WPAllImport will import ACF fields http://www.wpallimport.com/

    3) No. ACF uses the standard jQuery date field. To use a different type of calendar you would probably be looking at building a new field type add on plugin that uses a modified version of the datepicker like this one https://www.npmjs.com/package/persian-datepicker

  • I’m glad I found this post… I had the exact same problem with the Gallery Field.

    I personally decided to just add the php to all of my themes’ function.php & then “hide” the fields (in my case an entire option page called Site Content Settings) on my main site, as this was the only theme that didn’t require these fields.

    add_action( 'admin_menu', 'my_remove_menu_pages', 999  );
    function my_remove_menu_pages() {
        remove_menu_page('site-content-settings');   
    } 
    

    Bit messy, but everything works again. No one will every know 🙂

  • Not sure if this will do everything you want but there is a way to filter the capibility

    
    add_filter('acf/settings/capability', 'change_acf_cap', 20, 1);
    function change_acf_cap($cap) {
      // modify the capability required to access acf admin stuff
      return $cap;
    }
    

    I don’t know if you can use this to limit access to specific features or not.

    ACF has plenty of filters, much more than many other plugins I’ve worked with. But many of them require digging around in the ACF code to find. Searching all of the files for “apply_filters” and “do_action” is a good place to start when you’re looking for something specific.

Viewing 25 results - 10,426 through 10,450 (of 21,364 total)