Support

Account

Forum Replies Created

  • You should be able to get the post count after you run your query:

    For example:

    echo "<span>".$postslist->post_count."</span>";

  • I noticed an extra closing curly bracket. Not sure if that is it.

    I think your group field is like a repeater. I haven’t work with this field type, so I’d be guessing. I think you have to put if/while for your group inside your first repeater.

    The documentation is here:
    Group

    In other words, the group is nested in the repeater.
    I think the code should look something like this:

    function my_check_for_change($value, $post_id, $field) {
    
    		if( have_rows('r1') ): 
    			while( have_rows('r1')) : the_row() 
    			
    				if( have_rows('g1') ): 
    					while( have_rows('g1')) : the_row() 
    		
                        	update_sub_field( array('r1', 1, 'g1', 1, 't1'), 'cow' );
                        	update_sub_field( 't1', 1, 'cow');
                        	update_sub_field( 'g1_t1', 1, 'cow');
                        	update_sub_field( 'r1_g1_t1', 1, 'cow');													
    
    					endwhile; 	
            		endif;
    			endwhile; 	
            endif;
    
    	}
  • Please disregard the forum post. I think I figured it out.

  • I got this to work by adding $post_id to the get_field() function. And I needed to get the slug from the category object and not the name:

    	$sport = get_the_category(); 
    	$cat = $sport[0]->name; 
    	$away_team = get_field('away_team_2',$post_id)->ID;
    	$home_team = get_field('home_team_2',$post_id)->ID;
    
  • I will keep that error_log in mind for future projects. I got it to work by including $post_id in get_field() function.

    Here is the working code:

    function my_post_object_query( $args, $field, $post_id ) {
    
    $cat = get_the_category($post_id);
    $sport = $cat[0]->slug;
    
    /*
    echo '<pre>';
    	print_r($x['class']);
    echo '</pre>';
    */
    
    $round = get_field('round',$post_id);
    $division = get_field('class',$post_id);
    
    if($round == 'prelim'):
    	$next_round = 'quarterfinal';
    
    elseif($round == 'quarterfinal'):
    	$next_round = 'semifinal';
    
    elseif($round == 'semifinal'):
    	$next_round = 'regional final';
    
    elseif($round == 'regional final'):
    	$division = array('A','B','C','D');
    	$next_round = 'state_championship';
    
    else:
    	$division = array($division,'A','B','C','D');
    	$next_round = array('quarterfinal','semifinal','regional final','state championship');
    endif;	
    	
    
    $args = array(
       // 'meta_key' => 'game_date_2',// priority
       'orderby' => 'ID',
       'order' => 'ASC',
       'post_status' => 'publish',
       'post_type' => 'game',
       'posts_per_page' => 10,
       'category_name' => $sport,
       'meta_query' => array('relation' => 'AND',
    
            array(
                'key' => 'playoff_game',
                'value' => 1
                ),
    
             array('relation' => 'OR',
           array(
                'key' => 'class',
                'value' => $division,
                ),
    ),
            array('relation' => 'OR',
            		array(
                'key' => 'round',
                'value' => $next_round,//array('quarterfinal','semifinal','regional final','state hampionship'),
                ),
         	  ),
    
            ),
    
        );
    
        return $args;
     
    }
    
    // filter for every field
    // add_filter('acf/fields/post_object/query', 'my_post_object_query', 10, 3);
    
    // filter for a specific field based on it's name
    //add_filter('acf/fields/post_object/query/name=my_post_object', 'my_post_object_query', 10, 3);
    
    // filter for a specific field based on it's key
    add_filter('acf/fields/post_object/query/key=field_593060bd83376', 'my_post_object_query', 10, 3);
    
    

    This for your help with this!

  • Thanks for the response John.

    I don’t think any of those points you made are an issue, because when I substitute a string from one of the choices in the class pulldown, the query works as expected.

    I understand that the $post_id defaults to the current post, but I don’t know if something got changed with an update. It’s just not getting the $post_id from the current page for me.

  • That didn’t work. It returned the post id of the last post in the query of the get_away_record_update function and used that as the $home_team parameter of the get_home_record_update function. Thanks though!

  • I figured it out. There were conflicting functions.

  • I overlooked a place to store the price for each package. I was thinking that these would be hidden programmatically.

    So, you may have to create a field for the price of each of the package (nine fields). When creating the fields, set the default value for each one to the price you want.

    Then create a front-end form that only shows the fields that you want. You would still have access to price fields on the back end.

    The code for the functions file could look something like this, assuming these fields: pulldowns (hotel_level [values: 1,2,3], bedrooms [values:1,2,3]), text fields (price_1, price_2, price_3, price_4, price_5, price_6, price_7, price_8, price_8, price_9, total):

    function update_guest_package_price(){
    
    	$total_price = 0;
    
    if(get_field('hotel_level') == '1' && get_field('bedrooms')  == 1){
    	$total_price = get_field('price_1');
    	update_field( 'total', $total_price);
    		
    }
    
    elseif(get_field('hotel_level') == '1' && get_field('bedrooms')  == 2){
    	$total_price = get_field('price_2');
    	update_field( 'total', $total_price);
    		
    }
    
    elseif(get_field('hotel_level') == '1' && get_field('bedrooms')  == 3){
    	$total_price = get_field('price_3');
    	update_field( 'total', $total_price);
    		
    }
    
    elseif(get_field('hotel_level') == '2' && get_field('bedrooms')  == 1){
    	$total_price = get_f5eld('price_4');
    	update_field( 'total', $total_price);
    		
    }
    
    elseif(get_field('hotel_level') == '2' && get_field('bedrooms')  == 2){
    	$total_price = get_field('price_5');
    	update_field( 'total', $total_price);
    		
    }
    
    elseif(get_field('hotel_level') == '2' && get_field('bedrooms')  == 3){
    	$total_price = get_field('price_6');
    	update_field( 'total', $total_price);
    		
    }
    
    elseif(get_field('hotel_level') == '3' && get_field('bedrooms')  == 1){
    	$total_price = get_field('price_7');
    	update_field( 'total', $total_price);
    		
    }
    
    elseif( get_field('hotel_level') == '3' && get_field('bedrooms')  == 2){
    	$total_price = get_field('price_8');
    	update_field( 'total', $total_price);
    		
    }
    
    elseif(get_field('hotel_level') == '3' && get_field('bedrooms')  == 3){
    	$total_price = get_field('price_9');
    	update_field( 'total', $total_price);
    		
    }
    add_action('acf/save_post', 'update_guest_package_price', 20);

    I have not tested this code, but this is the general idea where you use conditional logic based on the selected fields to obtain the desired output.

  • Have you tried using the get_field_objects()?

    if you create a page with just the following code for the output, you can see array values for all the fields:

    $fields = get_field_objects($post_id);
    
    echo '<pre>';
    	print_r($fields);
    echo '</pre>';

    You should be able to get the information you need from there.

  • I think you’re going to need to use jQuery to run a script after the appropriate field has been selected. JQuery is JavaScript that you can use to manipulate values from the HTML.

    If I understand you, you have two fields: one for the hotel and one for the bedrooms. So, run jQuery after the second field is selected and store the price in a third field. You can do the same thing on the back end or calculate when the post is saved.
    I don’t think you need nine fields.

    You could have one pulldown with the hotel level, another with the number of bedrooms and a third text field that gets updated with the price after saving. That would be a simple IF ELSE script.

    Another option is to create one pulldown displaying and explaining the nine options, and setting the value of the option as the price. So what the person sees as is “Hotel level 1, 1 bedroom”, but the value of the choice is the price associated with that selection. This can be done when the ACF field is created.

    Hope this helps. I’m not entirely sure if I am seeing what you are trying to do though.

  • Thanks!

  • I thought that’s what might be happening. Thanks for responding.

  • I got this working by using the custom fields tool export to php. I must have omitted a parameter

  • I can’t thank you enough. You’re a livesaver. That export php code is a handy trick.

  • Thanks!

  • I’m still confused. In this page at WordPress, I see an example that looks like a path:

    <script type="text/javascript" src="/scripts/emailpage.js"></script>

    Are you saying that I register my script with a certain name, then put that name in the script below where it says ‘my-admin-js’?

    function my_admin_enqueue_scripts() {
    
    	wp_enqueue_script( 'my-admin-js', get_template_directory_uri() . '/js/example.js', array(), '1.0.0', true );
    
    }
    
    add_action('admin_enqueue_scripts', 'my_admin_enqueue_scripts');
Viewing 17 posts - 51 through 67 (of 67 total)

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.