Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • ** EDIT: I just saw that you answered so I’ll read through that. Disregard this answer for now!

    Also, I’m not sure I fully answered your question. Right now the loop is really basic. It takes in cikkek posts and is limited to a certain number of posts based on the layout.

    A picture might help a bit: https://imgur.com/npKU5SL

    The section I’m referring to is “kiemelt hirek”.

    So the top 3 positions are:

    1st loop: Take 1 cikkek post with acf options id from kiemelt 1
    2nd loop: Take 1 cikkek post with acf options id from kiemelt 2
    3nd loop: Take 1 cikkek post with acf options id from kiemelt 3

    I understand that I need to combine the loops somehow, but I’m unsure as to how I can achieve that. I would somehow need to assign

    $top1 = get_field(‘kiemelt1’, ‘option’); a value and order by that value.

    That would fix the looping issue for one, but not the others.

  • Sorry, still not sure I follow. I would set these fields up as post object fields to allow selecting a post rather than entering an ID manually.

    So, thinking about what you have this is the way I would do something similar.

    The options page has 9 post object fields that will appear and override specific positions. Each could be empty.

    I would get the values from these fields and I would query all the posts to get 9 posts in descending date order excluding any posts selected in the post object fields.

    I would then create a loop to show 9 posts using a counter to tell me what post from the query is next something like the following.

    Please note that this is just a rough idea and a lot of it would need to be filled in.

    
    $next_post = 0;
    for ($i=0; $i<9; $i++) {
      if (/* test for top post at this position */) {
        $post = {post at this position};
      } else {
        $post = $queried_posts[$next_post]
        $next_post++;
      }
      // show the selected post
    }
    

    What this would do is show the posts that are selected filled in with other recent posts up to the 9 needed and avoid showing any post twice.

    I can help flesh this out more if need be. I have actually created something like this before for a client. They wanted to events and to have a slider that showed the first X number of upcoming posts but they also wanted to be able to override any position in the slider with a “featured” event that may be further into the future.

  • Thanks for bringing me on the right way 🙂

    Now I can create a CPT including an options page with a Repeater. That’s super handy for me. Just the field group needs to be linked again from the acf settings to the new option page (is there any easy solution for automation?).
    For anyone looking for something similar, here the code from the functions.php. No clue if it’s perfect, but it works well for me.

    // CREATES CUSTOM POSTTYPE WITH OPTION PAGES
    function instrument_manager() {
    
    if( have_rows('instrument_manager', 'option') ):
    
        // add specific Option Pages for each CPT
        if( function_exists('acf_add_options_page') ) {
            
        while( have_rows('instrument_manager', 'option') ) : the_row();
    
            $post_type_title = get_sub_field('instrument_title', 'option'); //can be every title
            $post_type_slug = get_sub_field('instrument_slug', 'option'); //no special chars, no caps
    
            acf_add_options_sub_page(array(
                'page_title'     => 'Settings ' . $post_type_title,
                'menu_title'     => 'Settings ' . $post_type_title,
                'parent_slug'    => 'edit.php?post_type=' . $post_type_slug,
                'post_id'        => 'options_' . $post_type_slug,
            ));
        endwhile;
        }
    
        // create Custom Post Types 
        function create_posttype() {
        while( have_rows('instrument_manager', 'option') ) : the_row();
    
            $post_type_title = get_sub_field('instrument_title', 'option');
            $post_type_slug = get_sub_field('instrument_title', 'option');
    
            $lables = array('name' => __( $post_type_title ), 'singular_name' => __( $post_type_title ));
            $args = array(
                'labels' => $lables,
                'public'            => true,
                'publicly_queryable' => true,
                'supports'          => array( 'title', 'editor', 'page-attributes' ),
                'taxonomies'        => array( 'category', 'post_tag' ),
            );
            register_post_type( $post_type_slug , $args ); 
        endwhile;
        }
    
    endif;
    }
    add_action('init', 'instrument_manager');
    add_action( 'init', 'create_posttype' );
    
    

    and to read out the settings in my archive.php I used this line:

        $post_type = 'options_' . get_query_var('post_type');
    the_field('field-name', $post_type) ?>
    
  • You have to do a WP_Query to get posts using a meta query, if you are just looking to see if any if it is checked anywhere then you could limit the query to return one ID

    
    $args = array(
      'post_type' => 'your post type',
      'post_status' => 'pubish',
      'posts_per_page' => 1,
      'fields' => 'ids',
      'no_found_rows' => true,
      'meta_query' => array(
        array(
          'key' => 'checkbox field name',
          'value' => '"'.$field_value_to_find.'"',
          'compare' => 'LIKE'
        )
      ),
    )
    $my_query = new WP_Qeury($args);
    if (!empty($my_query->posts)) {
      // there is a post with this value checked
    }
    
  • To expand on that, when saving options ACF saves the values to the options table and the option_name value is prefixed with “options_”, for example “options_my_text_field”. When you specify a different post ID like “my_cpt_options” the same field will be saved with the name “my_cpt_options_my_text_field” making the two entries unique.

  • I don’t know what I was thinking when I first answered this question. Looking back at the OP now I don’t see any reason this should not be working.

    How are the original fields added?

  • Hi, I know this is older thread, but I ran into same problem and fixed it in a similar way @jeremynative did.

    Addind a tag with class “fancybox-img” and actual url of full size img as href worked for me.

    I was basically doing image swiper and in a loop when I was generating images I just added a tag mentioned above.

    Here is my code (notice the a tag i added on img):

    
            <div class="swiper-container gallery-swiper">
    			<div class="swiper-wrapper">       
                    <?php 
                        $gallery = get_field("galerie");
                        if ($gallery)
                            foreach ( $gallery as $img ){
                                ?>
                                <div class="swiper-slide">
                                    <a class="fancybox-img" href="<?php echo esc_url($img['url']);?>">
                                        <img src="<?php echo esc_url($img['sizes']['homepage-nav']);?>" link=file alt="<?php esc_attr($img['alt']);?>"/>
                                    </a>
                                </div>
                                <?php
                            }
                    ?>
    			</div>
    
                <div class="swiper-button-next"></div>
                <div class="swiper-button-prev"></div>	
    		</div>  

    Hope tihs will be helpfull to someone.

  • What I ended up doing is extending “acf_field_relationship” with my own classname “acf_field_relationship_nogroup”. A few things needed to be customized, and I needed to register the new control in jQuery as well. It seems to be working well.

    Seems like not grouping the results by post type should be an option for Relationship fields though.

  • Hey John, sorry for bringing this up again, but since I was having a hard time explaining the issue, I decided to just poke around until I figured it out but I’m still having problems.

    I think a simpler explanation is that the default way of displaying my posts in the relationship field is like this:

    Bios
    Jack Brown
    Jane Smith
    John Doe
    
    Resumes
    Jack Johnson
    James Thompson

    But I need the results to simply display like this:

    Jack Brown
    Jack Johnson
    Jane Smith
    James Thompson
    John Doe

    So no grouping by post type. I’ve poked around in the code and the get_ajax_query function calls the function acf_get_grouped_posts which groups the results by post type, and as far as I can see there’s no way to bypass the grouping function. So I’m thinking I need to create a custom ACF Relationship field/plugin that doesn’t call the acf_get_grouped_posts. I just want to check in real quick and see if I’m missing something before doing that, since it’s not an ideal solution.

    Thanks you!

  • Oh, I didn’t realize this thread was accidentally submitted twice, sorry for that.

    In the other one with the same title I think I already answered my own question, which wasn’t about the nonce value generated in the form field, but the value returned in the $_POST.

    I found this with respect to the latter:

    According to this document listing acf code –

    https://docs.wpdebuglog.com/plugin/advanced-custom-fields/5.8.8/function/acf_verify_nonce/

    acf resets the nonce to “false” upon verification so the form can only be submitted once with this nonce. So “false” as value for ‘acf_nonce’ in the $_POST actually means ‘verified’, if I’m not mistaken.

    Although I wonder if changing “false” to “verified” for “acf_nonce” in the $_POST may make it easier to understand what is going on?

    Thanks for your reply!

  • To the OP, this generally happens when something in interfering with a query being done by ACF. It could be that another plugin was causing the issue or that it is a but in WP as @lukasfrei experienced.

    The first thing that needs to be done is to narrow down the problem, update or revert WP, plugin deactivation, theme switching to figure out where the conflict is.

  • You cannot select specific fields, repeater or otherwise, but especially repeaters, to display on another post, at least not without a lot of custom coding.

    The issue is that you are selecting a page and I am assuming by reading your description that every page can have a different repeater. In this case you would need to have at least 2 field. One where you select the related page and a second where you select the rows of the repeater you want to so. To do this you would need to build custom JavaScript that is fired when the first field is changed that then does an AJAX query and populates the possible values in the second field.

    An alternate, easier option would be to add a true/false field to the repeater to select which rows to show when they are shown on the product page.

    Unless this repeater is on an options page and that would require something completely different.

  • Just did a quick look at a site that is using acf_form and I find this in the generated form

    
    <input type="hidden" id="_acf_nonce" name="_acf_nonce" value="17630f97db">
    

    I do not know what is causing this on your site. I would start by seeing if there is some type of plugin conflict by deactivating other plugins. Also not the difference in the field name, on my site it starts with an underscore (_)

  • You would need to create an acf/fields/relationship/query filter.

    In this filter you would need to do gather al list of all of of the players already selected for other teams. To do this you would need to do a query to get all of the teams and then get the players field from each post and make a list of post IDs in an array. They you would use these results in the “post__not_in” argument for the query.

  • There is an example of searching by the beginning of strings here https://stackoverflow.com/questions/31571864/select2-search-match-only-words-that-start-with-search-term

    You would need to add custom JS to your site and to something like that. Sorry, I don’t know the exact details or code to add this to an ACF field.

  • You need to supply the $post_id argument for have_rows(). This can either be a term object or it can be "term_{$term_id}"

    In category.php you can use

    
    $queried_object = get_queried_object();
    

    and then

    
    ... have_rows('taxonomy_gallery_lightbox_image', $queried_object) ...
    
  • If I understand you want to include posts that are in 2 categories but exclude them if they are also in a third category.

    I.E. Show if in category 76 but not if it is also in category 78.

    I think that in order to do this you need to use a tax_query. I could be wrong but I do not think the ‘cat’ argument can be used the way you are trying to use it and I also thing that using ‘category__in’ combined with ‘category__not_in’ will work the same way. Like I said, I could be wrong but I think these arguments work as ‘OR’ (meaning category 76 OR not category 78).

    
    $args['tax_query'] = array(
      'relation' => 'AND',
      array(
        'taxonomy' => 'category',
        'field' => 'term_id'
        'terms' => array(76, 77),
        'operator' => 'IN'
      ),
      array(
        'taxonomy' => 'category',
        'field' => 'term_id'
        'terms' => array(78),
        'operator' => 'NOT IN'
      )
    );
    
  • Can can either use CSS to hide the button or you could possibly add custom javascript to remove the button completely.

    
    (function($){
      if (typeof(acf) == 'undefined') {
        return;
      }
      acf.add_action('ready append', function(e){
        $('a.acf-icon.-duplicate').remove();
      });
    })(jQuery);
    
  • Yoast will index the content associated with the FAQ post but will not include that on the page/post where you have created the relationship to that other post because the content is not part of that post (in your example the about us page).

    To do this you would need to copy the question and answer to either the content of the about us page or fields associated with the about us page.

    However, this indexing that you speak of is only an admin indexing and it does not have any impact on search engines. But if you want it for the admin report for the page then the only way to do it is to copy the content.

  • The posts may or may not be ordered in the same order that they are selected, there isn’t any way to tell. There isn’t a simple way to order posts by post type. You would need to modify the sql query that is being done by adding a filter before the query and then removing it when you’re done. Here is an example of altering results by post type. You’d need to modify it to also add ordering by title. https://stackoverflow.com/questions/15675296/wordpress-order-posts-by-post-type

  • SORRY for highjacking your thread.

    Any change you could share a working demo of a custom implementation?

    Currently i’m trying to see if i can make the following field working https://github.com/kevinruscoe/acf-star-rating-field/tree/master with acf’s conditional logic.

    So i added the to the input.js

    var star_field = acf.Field.extend({ type: 'star_rating_field' });
    		acf.registerFieldType(star_field);
    		acf.registerConditionForFieldType('equalTo', 'star_rating_field');

    .

    Now i’m able to select conditions in other fields and select that field. The only issue is the conditions are not working so i have the feeling i’m missing some code to make this to work. Any ideas?

  • You cannot do a query on this field in that way. In fact, I’m surprised that you first query works correctly. It should be something like this

    
    $postsargs = array(
    	'posts_per_page'   => 5,
    	'post_type'        => 'post',
    	'post_status'      => 'publish',
    	'meta_query'	=> array(
    		array( 
    			'key'	 	=> 'destinations', 
    			// not the " around the ID
    			'value'	  	=> '"'.$destid.'"', 
    			'compare' 	=> 'LIKE'
    		)
    	)
    );
    $getposts = get_posts( $postsargs );
    

    The only way that that your original query can work is if the ID number value is unique within the serialized array stored in the DB.

    ACF stores the field as a serialized array. To query for mulitple values requires doing something like this

    
    $postsargs = array(
    	'posts_per_page'   => 5,
    	'post_type'        => 'post',
    	'post_status'      => 'publish',
    	'meta_query'	=> array(
    		'relation' => 'OR',
    		array( 
    			'key'	 	=> 'destinations', 
    			'value'	  	=> '"'.$destinations_1_id.'"', 
    			'compare' 	=> 'LIKE'
    		),
    		array( 
    			'key'	 	=> 'destinations', 
    			'value'	  	=> '"'.$destinations_2_id.'"', 
    			'compare' 	=> 'LIKE'
    		),
    		// etc for each destination
    	)
    );
    $getposts = get_posts( $postsargs );
    

    With a lot of destinations this query will cause performance issues. My suggestion would be to set up a bidirectional relationship field for these posts.

  • @jongc

    There is a way to do this, but not by using the admin controls and I can’t give you the full code because it would be fairly complicated.

    What you need to do is to alter the conditional logic of the field. This can be accomplished but creating an acr/prepare_field filter for the field in questions. In this filter you would look at $field[‘parent’] and this might let you determine if the field is used in the way you have it set up. If you can, and it is, then you could alter the conditional logic for the field to make it work the way you want it to.

    I have done similar things in the past. This code is an example from a recent project and I use this filter to remove sub fields base on the parent field in some cases.

    
    function remove_fields_on_theme_options($field) {
      
      // remvove some layout fields on options page
      $fields = array(
        'field_5ea2ea8fa0ca2'
      );
      if (in_array($field['key'], $fields)) {
        $parents = array(
          'field_5f32b07ae9253'
        );
        if (in_array($field['parent'], $parents)) {
          return false;
        }
      }
      
      // remove all layout fields and CTA tab inside of quick links
      $fields = array(
        'field_5ea2ea8fa0ca2',
        'field_5eadd1ef885d1',
        'field_5ea5d1d7a83e2',
        'field_5ea5d209a83e3',
        'field_5ddf3c9274fd1'
      );
      $parents = array(
        'field_5f15c8a928f77',
        'field_5f18749c26e32',
        'field_5f1877143d7e0',
        'field_5f32997382af7',
        'field_5f32a577f5900'
      );
      if (in_array($field['key'], $fields) && in_array($field['parent'], $parents)) {
        return false;
      }
      
      return $field;
    }
    
  • Not only would you need to hide the tab but you would also need to filter and hide all of the fields in that tab.

    You do not want to unset the field, you need to return false

    
    // Apply to fields named "example_field".
    	add_filter('acf/prepare_field/key=field_60647c32d82ce', 'hide_ani_tab');
    
    	function hide_ani_tab($field) {
    
    		if ( false == get_field( 'animation_option', 'option' ) ) {
    			// remove tab by field key
    			return false;
    		}
    
    		return $field;
    	}
    

    but as I said, this would need to be done for the tab and all of the fields in the tab

  • These solutions all require you to manually bump the version number in your composer.json every time there’s a release. If you manage more than one or two sites, this is a huge pain.

    Created this as a general-purpose alternative. Can be set up for ACF and should work for a variety of other private plugins/themes.

Viewing 25 results - 5,726 through 5,750 (of 21,329 total)