Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • That would dependent on what you are building with and would best be a question for the developers of that solution.

    Terms in WP do not have “Featured Images”

  • Yes, you could do it that way but you would need to have a relationship field on each “Edition” post to connect to all the “Books”. If you don’t then you’d still be looking at doing a query of all the books and looping to find the right ones.

    The main issue is that you have the “Edition” type in a repeater and it is difficult to search by a repeater sub field, there is some documentation about it on this page https://www.advancedcustomfields.com/resources/query-posts-custom-fields/. If you do this the performance will not be good.

  • I have also been having this issue on my custom post types and I noticed that removing preview=true from the url query strings shows all the ACF custom fields.

    I am using WP 6.4.1/ ACF PRO 6.2.2.

  • I take that back, given what you have there isn’t any way to create page that lists books by “Edition” unless you query all books and then loop over the repeater for every book to see if it has that edition.

  • Hate to be a downer, but this is going to be difficult.

    Given what you have you will need to do something like this: https://www.advancedcustomfields.com/resources/how-to-sorting-a-repeater-field/

    I would likely have made the “Books” CPT and then used child posts to create the “Editions” and separated the custom fields between parent/child posts based on what they applied to. This way you could show child posts on the parent post CPT and you could query all child posts by the “Type” taxonomy page (template: archive-{$taxonomy}.php} to show lists of books for each type.

  • Hi John,
    I figured out what went wrong in the first place.
    In your solution:

    
    if (get_field('your_field_name') != $last_value) {
            // ourput heading for next section
            // your code here
            
            // set last value to this value
            $last_value = get_field('your_field_name');
          }
    

    you get the data with get_field('your_field_name') from the first item in the database, in my case this was always 3. So it is not the data from the first item in the query. And that’s why I got stucked.
    After some serious thinking and a lot of trial and error I came up with this solution where I use a For loop to get everything organised by label (division):

    
    // Get the values from the ACF object (radio buttons)
    $all_names = get_field_object('medewerker_werkzaam_bij');
    // Put the choices from that object in an array 
    $all_label_names = $all_names['choices'];
    // Count the number of items to use in the 'For' loop. Because a loop starts with '0', decrease the value for that variable with 1				
    $num_labels = count($all_label_names)-1;
    
    for ( $my_label = 0; $my_label <= $num_labels; $my_label++ ){
    	$all_query = new WP_Query(array(
    		'post_type'			=> 'collegas',
    		'posts_per_page'    => -1,
    		'meta_query' 		=> array (
    									'label' 	=> array (
    										'key' 	=> 'medewerker_werkzaam_bij',
    										'value' => $my_label,
    									),
    									'persoon' 	=> array (
    										'key' 	=> 'medewerker_achternaam',
    									),
    								),
    		'orderby'			=> array (
    									'label' 	=> 'ASC',
    									'persoon'	=> 'ASC',
    		)
    	));					
    	if ( $all_query->have_posts() ) {
    	$my_label_name = $all_label_names[$my_label];
    
    	<h2 id="<?php echo $my_label_name; ?>" class="<?php echo $my_label_name;?>"><?php echo $my_label_name;?></h2>
    	<div class="<?php echo $column_class; ?>">
    		while ( $all_query->have_posts() ) {
    			$all_query->the_post();
    			get_template_part( 'loop-templates/content-collegas', get_post_format() );
    		}
    	} else {
    		get_template_part( 'loop-templates/content', 'none' );
    	}
    	</div>
    }
    
    

    This works for me as I wanted it in the first place.
    But thank you for replying and pushing me in the right place

  • Hi John,
    I figured out why it was not working.
    In your suggestion:

    
    if (get_field('your_field_name') != $last_value) {
            // ourput heading for next section
            // your code here
            
            // set last value to this value
            $last_value = get_field('your_field_name');
          }
    

    the data you get from get_field('your_field_name') is the data you get from the first item in the database, not the data from the query. In my case it was always ‘3’.
    I rewrote the entire loop, and now it looks like this:

    
    // Get the values from the radio buttons from the ACF object
    $all_names = get_field_object('medewerker_werkzaam_bij');
    // Get the choices from those radiobuttons and put them in an array
    $all_label_names = $all_names['choices'];
    // Count the number of items in the array to use in the 'For' loop. Because a loop starts with '0', decrease the value in the variable with 1				
    $num_labels = count($all_label_names)-1;
    
    for ( $my_label = 0; $my_label <= $num_labels; $my_label++ ){
    $all_query = new WP_Query(array(
    'post_type'			=> 'collegas',
    'posts_per_page'    => -1,
    'meta_query' 		=> array (
    'label' 	=> array (
    'key' 	=> 'medewerker_werkzaam_bij',
    'value' => $my_label,
    ),
    'persoon' 	=> array (
    'key' 	=> 'medewerker_achternaam',
    ),
    ),
    'orderby'			=> array (
    'label' 	=> 'ASC',
    'persoon'	=> 'ASC',
    )
    ));					
    if ( $all_query->have_posts() ) {
    $my_label_name = $all_label_names[$my_label];
    ?>
    <h2 id="<?php echo $my_label_name; ?>" class="<?php echo $my_label_name;?>"><?php echo $my_label_name;?></h2>
    <div class="<?php echo $column_class; ?>">
    <?php	
    	while ( $all_query->have_posts() ) {
    		$all_query->the_post();
    		get_template_part( 'loop-templates/content-collegas', get_post_format() );
    			}
    		} else {
    			get_template_part( 'loop-templates/content', 'none' );
    		}
    			?></div><?php
    		}
    

    And now I have exactly what I was looking for.
    Thanks for replying and moving me in the right direction.

  • Hi John,

    I’m afraid your solution is not working for me.
    Think I need a ‘foreach’ loop to get this working the way I want.
    This is what I’m looking for:

    
    -- Division Name 1 ---
    Person 1
    Person 2
    Person 3
    
    -- Division Name 2 ---
    Person 1
    Person 2
    
    -- Division Name 3 ---
    Person 1
    Person 2
    Person 3
    Person 4
    Person 5
    
    etc.

    This means that I need to know what value (showing part of the query of my earlier post) is in

    
    'label' 	=> array (
    			'key' 	=> 'medewerker_werkzaam_bij',
    		),
    

    The value should range from 1 to 7. But I really have no idea how to put that value (an ACF field) into a variable so I can check / validate that in a foreach or while loop.

  • I don’t really understand what the issue is. Maybe if you supply more detail someone can help. Otherwise I would suggest contacting the author or the “Advanced Queries” plugin.

  • This will work the same way whether using blocks or not using blocks.

    To summerize and make sure I’m not missing anything.

    You have two fields in your group

    1. A Taxonomy Field
    2. A Post Object Field

    And you want to filter the posts available for selection in the post object field by the selected term.

    This is not possible without custom coding. You will need to add custom JavaScript to ACF and you will need to use the ACF JS API.

    In your JS code you will need to use the select2_ajax_data hook and get the value selected in the taxonomy field and add it to the values submitted in the AJAX request.

    Then in your acf/fields/post_object/query filter you will need to get this value from $_POST and use the value to alter the query done for the post object field.

    You may also need to trigger a refresh of the post object field or delete any value that is already selected in the post object field if the term selected in the taxonomy field is changed. I don’t have any references on how to do this part.

  • This is not something that ACF can do, or for that matter, any plugin that allows you to add CPTs and custom taxonomies. This is something that comes up often now that ACF is doing this.

    See some of the previous topics on this subject

  • I know that the forum is “Feature Requests” but these forums are old and the developers to not look at them. You can contact or submit your feature request in a number of ways.

    1. Feedback Page
    2. Contact Form
    3. Open a ticket in your account
  • There is a solution here for accepting only unique values https://support.advancedcustomfields.com/forums/topic/accept-only-unique-values/#post-45359

    It is rather simple, but yes, you would need to validate both the start and end date and you would have to do one or more queries check the posts. Yes it would be complicated because you’re talking about (I think) basing uniqueness on 3 different fields.

  • 
    if ( $all_query->have_posts() ) {
      // add a variable that will treack tha last section shown
      $last_value = '';
      ?>
      <h2 id="opmeer" class="">Iedereen</h2>
      <div class="<?php echo $column_class; ?>">
        <?php
        // Start the loop.
        while ( $all_query->have_posts() ) {
          $all_query->the_post();
          
          // check the value of this against last shown
          if (get_field('your_field_name') != $last_value) {
            // ourput heading for next section
            // your code here
            
            // set last value to this value
            $last_value = get_field('your_field_name');
          }
          
          
          get_template_part( 'loop-templates/content-collegas', get_post_format() );
        }
    } else {
      get_template_part( 'loop-templates/content', 'none' );
    }
    
  • The URL will only take a web page URL and there isn’t a way to alter this.

    I use the following to add a setting to use text field an validate

    
    <?php 
    
      add_action('acf/render_field_validation_settings/type=text', 'validate_text_as_href_setting');
      add_action('acf/validate_value/type=text', 'validate_text_as_href', 10, 4);
        
      function validate_text_as_href_setting($field) {
        // this adds a setting to text fields
        // setting it to true will require that the content of the fields
        // meets requirements to be used as a link href value
        $args = array(
          'label' => 'Validate as HREF',
          'instructions' => 'Require a valid href attribute. This includes values starting with: http://, https://, ftp://, mailto:, tel:, sms:, /, and #',
          'type' => 'true_false',
          'name' => 'validate_href',
          'ui' => 1,
          'class' => ''
        );
        acf_render_field_setting($field, $args);
      }
        
      function validate_text_as_href($valid, $value, $field, $input) {
        // if the setting created by validate_text_as_href_setting
        // is true than this filter will test input to ensure it can
        // be used in as a link href value
        // this allows links starting with
        // / (site root relative), http://, https://, ftp://, # (anchor), mailto:, tel:, sms:
        if (!$valid) {
          return $valid;
        }
        // does setting exist and is it set
        if (!empty($field['validate_href'])) {
          // only validate if value submitted (use acf required setting to require value)
          if (!empty($value)) {
            // allow anything that looks like a valid href value
            if (!preg_match('%^(https?\://|ftp\://|/|#|mailto\:|sms\:|tel\:)%', $value)) {
              $valid = 'Enter a Valid Link HREF Value';
            }
          }
        }
        return $valid;
      }
    
  • Also managed to solve this reading trough this topic, thank you all! My solution may work for others so also posting it here:

    In my “block.json”:

    {
        "name": "acf/my-acf-block",
        "title": "My ACF Block",
        "description": "Description of this block.",
        "style": "file:./my-acf-block.css",
        "category": "my-custom-category",
        "icon": "random-icon-or-svg",
        "textdomain": "my-textdomain",
        "acf": {
            "mode": "edit",
            "renderTemplate": "my-acf-block.php"
        },
        "supports": {
            "align": [
                "full"
            ]
        },
        "example": {
            "attributes": {
                "mode": "preview",
                "data": {
                    "preview_image_my_acf_block": "assets/img/my-placeholder.jpg"
                }
            }
        }
    }

    And in “my-acf-block.php” I start with:

    <?php
    
    if( isset( $block['data']['preview_image_my_acf_block'] )  ) {
    	
    	echo '<img src="' . CONSTANT_THEME_URL . $block['data']['preview_image_my_acf_block'] . ' " style="width: 100%; height: auto;">';
    	
    	return;
    
    }
    
    // the rest of my template render..
    ?>
    

    The “CONSTANT_THEME_URL” is a constant that I normally define within my theme and returns the URL of the current theme, but including trailingslashit().

  • When it comes to optimizing YouTube embeds for the best loading performance, there are a few key considerations to keep in mind. Firstly, it’s recommended to use the iframe embed code provided by YouTube, as it offers improved compatibility and automatic responsiveness for different devices. Additionally, you can enhance loading speed by specifying the video dimensions to match the container size on your website, reducing unnecessary rendering and resizing. Enabling lazy loading can also be beneficial, as it defers the loading of the YouTube player until the user interacts with it, improving initial page load times. Lastly, leveraging caching techniques, such as browser caching or content delivery networks (CDNs), can help deliver the video content more efficiently. By implementing these strategies, you can ensure a smooth and optimized YouTube embedding experience for your website visitors. Happy embedding!

  • thank you John for trying to help me. I told you that for group authorizations I use USER ROLE EDITOR which works very easily and without coding anything, it is very easy to manage that with this plugin. My ONLY question is in the creation of users, to be able to assign them in these groups created by ACF, that’s all 😉

  • You can put them in groups using an ACF select type field.

    The real question is what are you going to use the field for. No matter what way you turn you’ll need to either do something like adding the roles mentioned or doing a custom query on users with a meta_query on the field to get users in a specific group.

    And if you’re talking about limiting access to certain pages based on this value, then in either case it’s going to require custom coding.

  • I may have misspoke because WP does not support taxonomies on users. That option would really not be viable.

    The best option I can think of is to use user roles

    What you would really need to do is to create a select box with the groups. Then you’d have to use an acf/save_post action to get the value selected and set the user’s role based on the values saved in the field.

    In your action you’d want to make sure a user is being created or saved, the $post_id value in this case would start with “user”, (ie: "user_{$user_id}").

  • that’s part of the question I’m asking myself too 🙂 These will be user groups. Imagine a company for example: You have the Staff, the Office and the Management. This group can see this page but not another, this group can see ALL the pages etc… I know how to manage this, regarding permissions, with USER ROLE EDITOR which I already have.

  • I don’t know what you mean by

    assign them to one or more user groups

    Is this an ACF field? What type of field? A user Role? A taxonomy? A post?

    Unless you’re doing something special then it should be as easy as adding the field group to the WP registration form by setting the field group location rules.

  • You cannot use date_default_timezone_set() when working with WP. There was a change in WP 5.3 that broke the use of this function.

    See https://docs.wpvip.com/technical-references/code-quality-and-best-practices/local-time/

  • No one from the ACF “team” monitors these forums. If you want to talk to support then you need to contact them directly with this form or open a ticket on your account.

    But as I said, you cannot refine a query by data in another post. The only thing available for searching a post would be the post ID of the other post saved in the field. This is what I understand from your OP.

  • Is this achieved by using the Wrapper Attributes under the Presentation tab for the field inside a field group?

    Yes, you set the % width of each field

Viewing 25 results - 3,051 through 3,075 (of 21,345 total)