Support

Account

Forum Replies Created

  • I would loop through all the information and assign it to an array.

      Declare the array outside the loop.
      Add items to the array inside the loop and classify as expired or not.
      Sort the array by expire, date, title, etc.
      Loop through the array and output what you.

      The code below is UNTESTED, but it gives you an idea of how I would go about it.

    <?php
    
    //declare array
    $events = array();
    date_default_timezone_set('America/Los_Angeles');
    
    $today = strtotime(date('Ymd'));
    
    if (have_rows('events')): while (have_rows('events')) : the_row(); 
    
    //get the expire date
    	$expire = strtotime(get_sub_field('expire_on'));
    
    //compare it to today and assign it a value
     	if($expire < $today):	
    		$events[]['expired'] = true;
    	else:
    		$events[]['expired'] = false;
    	endif;	
    
    //assign the other information to key/value in the array
     	
    	$events[]['events_date'] = strtotime(the_sub_field('events_date'));
    	$events[]['events_title'] = the_sub_field('events_title');
        $events[]['events_location'] = the_sub_field('events_location');
    
    endwhile; endif; 
    
    //assign some variables for sorting
    foreach ($events as $key => $row) {
        $ev_expire[$key]  = $row['expired'];
        $ev_date[$key] = $row['events_date'];
        $ev_title[$key] = $row['events_title'];
        $ev_location[$key] = $row['events_location'];
    }
    //sorts by 'expired' (true first), then by date (descending), then by title (ascending)
    array_multisort($ev_expire, SORT_DESC, $ev_date, SORT_DESC, $ev_title, SORT_ASC,$events);
    
    //loop through the array and echo out the info if the event has expired
    
    foreach ($events as $event){
    
    		if($event['expired'] == true) {
         		echo "<div class='events-row expired'>";
           		echo "<h2>".$event['events_title']."</h2>";
           		echo "<h3>".date('Ymd',$event['events_date'])."|".$event['events_location']."</h3>
             </div>";
     		}
    
    }
    
    ?>
  • You have to use a front end form. The documentation is here.

    Basically, you change the settings below to fit your needs and add the acf_form($settings); where you want the form to appear.

    It involves programming, so you have to have access to the WordPress theme files.

    If you want this to appear on the Edit-tours.php page you have to add the coding to that file.

    This: <?php acf_form_head(); ?> goes at the top of your file ahead of get_header();.

    $settings = array(
    
    	/* (string) Unique identifier for the form. Defaults to 'acf-form' */
    	'id' => 'acf-form',
    	
    	/* (int|string) The post ID to load data from and save data to. Defaults to the current post ID. 
    	Can also be set to 'new_post' to create a new post on submit */
    	'post_id' => false,
    	
    	/* (array) An array of post data used to create a post. See wp_insert_post for available parameters.
    	The above 'post_id' setting must contain a value of 'new_post' */
    	'new_post' => false,
    	
    	/* (array) An array of field group IDs/keys to override the fields displayed in this form */
    	'field_groups' => false,
    	
    	/* (array) An array of field IDs/keys to override the fields displayed in this form */
    	'fields' => false,
    	
    	/* (boolean) Whether or not to show the post title text field. Defaults to false */
    	'post_title' => false,
    	
    	/* (boolean) Whether or not to show the post content editor field. Defaults to false */
    	'post_content' => false,
    	
    	/* (boolean) Whether or not to create a form element. Useful when a adding to an existing form. Defaults to true */
    	'form' => true,
    	
    	/* (array) An array or HTML attributes for the form element */
    	'form_attributes' => array(),
    	
    	/* (string) The URL to be redirected to after the form is submit. Defaults to the current URL with a GET parameter '?updated=true'.
    	A special placeholder '%post_url%' will be converted to post's permalink (handy if creating a new post)
    	A special placeholder '%post_id%' will be converted to post's ID (handy if creating a new post) */
    	'return' => '',
    	
    	/* (string) Extra HTML to add before the fields */
    	'html_before_fields' => '',
    	
    	/* (string) Extra HTML to add after the fields */
    	'html_after_fields' => '',
    	
    	/* (string) The text displayed on the submit button */
    	'submit_value' => __("Update", 'acf'),
    	
    	/* (string) A message displayed above the form after being redirected. Can also be set to false for no message */
    	'updated_message' => __("Post updated", 'acf'),
    	
    	/* (string) Determines where field labels are places in relation to fields. Defaults to 'top'. 
    	Choices of 'top' (Above fields) or 'left' (Beside fields) */
    	'label_placement' => 'top',
    	
    	/* (string) Determines where field instructions are places in relation to fields. Defaults to 'label'. 
    	Choices of 'label' (Below labels) or 'field' (Below fields) */
    	'instruction_placement' => 'label',
    	
    	/* (string) Determines element used to wrap a field. Defaults to 'div' 
    	Choices of 'div', 'tr', 'td', 'ul', 'ol', 'dl' */
    	'field_el' => 'div',
    	
    	/* (string) Whether to use the WP uploader or a basic input for image and file fields. Defaults to 'wp' 
    	Choices of 'wp' or 'basic'. Added in v5.2.4 */
    	'uploader' => 'wp',
    	
    	/* (boolean) Whether to include a hidden input field to capture non human form submission. Defaults to true. Added in v5.3.4 */
    	'honeypot' => true,
    	
    	/* (string) HTML used to render the updated message. Added in v5.5.10 */
    	'html_updated_message'	=> '<div id="message" class="updated"><p>%s</p></div>',
    	
    	/* (string) HTML used to render the submit button. Added in v5.5.10 */
    	'html_submit_button'	=> '<input type="submit" class="acf-button button button-primary button-large" value="%s" />',
    	
    	/* (string) HTML used to render the submit button loading spinner. Added in v5.5.10 */
    	'html_submit_spinner'	=> '<span class="acf-spinner"></span>',
    	
    	/* (boolean) Whether or not to sanitize all $_POST data with the wp_kses_post() function. Defaults to true. Added in v5.6.5 */
    	'kses'	=> true
    			
    );
    			
    
    	acf_form($settings);
  • Try this and let me know what you get:

    $args = array( 
        'post_type' => 'cars', 
        'posts_per_page' => 999,
        'meta_key' => 'price',
        'meta_type' => 'NUMERIC',
        'orderby' => 'meta_value_num',
        'order' => 'ASC'                        
    );
  • You could do this with jQuery. Why not just use a repeater?

  • Thanks John, I use this but I think post locking can only be done on the back end.

  • I found this on the web. Don’t know a lot about custom shortcodes, but I tested this and it worked.

    $shortcode = get_post_meta($post->ID,'YOUR_CUSTOM_FIELD_NAME',true);
    echo do_shortcode($shortcode); 
  • I would add a post object field to your flexible content field that returns the page ID. It provides a page link. When you loop through the flexible content field you can add logic: if the post object field = the page you want the content to appear, echo the WYSIWYG field. I can guide you through this if you are unfamiliar.

  • Your post object is alrwady set to return an ID, but you have $post_object->ID. Remove the ->ID and it should work.

  • Just set up your radio button with yes and no as choices.

    When you go to display the field, your code will be something like this:

    if( get_field('yes_no') == 'Yes':
        echo "<label style='color:green'>Yes</label>";
    elseif( get_field('yes_no') == 'No'):
        echo "<label style='color:red'>No</label>";
    else:endif;
  • I think you are trying to pass an array in the update field function and you haven’t defined a field. I think you need to pass a number to the post object. You may want to add another variable to get the page ID.

    Whatever $nombre_cargo is, you need to use the field name or field key as the first parameter of the update field function. For example: ‘nombre_cargo’ or ‘field_123456890’

    Try this, but replace the name of the field first.

    $per_obj = get_page_by_title( $resp, OBJECT, 'persona' );
    				
    if (!is_null($per_obj)) {
    	
            $page = per_obj->ID;
    } 						
    update_field( 'cargo_number', $page, $post_id );
  • If I understand you correctly, it looks like you are trying to get the choices in the post object to display in alphabetical order.

    Have you tried the following:

    function my_post_object_query( $args, $field, $post_id ) {
        
        // modify args
        $args['orderby'] = 'title'; //title of the post
        $args['order'] = 'ASC'; //order a-z; use DESC for z-a
        
        
        // return
        return $args;
        
    }
    
    add_filter('acf/fields/post_object/query/key={field key}', 'my_post_object_query', 10, 3);

    Change the field key to the field key for your post object (it should look like this: acf/fields/post_object/query/key=field_508a263b40457 . Then add the code to your functions.php file

    Documentation Hier

  • What type of field is your project_total_prints field? I’m assuming it is a WYSIWYG field. And are you trying to get the number of media (pictures) that have been uploaded to this field?

  • I’m not sure if you just want the content or if you want the ability to have that field when you edit the page.

    If you are tying to get the content, you would just add echo get_field(‘what_we_do’,[post_ID of the page]);

    If you want it to appear when you edit a page, just create a new location rule for that page:

  • Please show your code and list all the fields in the repeater. I can’t tell how many date fields you have. You should be able to loop through the sub fields. I’m willing to help.

  • Instead of adding 16 individual boxes, I would put the boxes that are going to hold the scores inside the player post in a repeater. You can set the minimum and maximum rows to the number of games in the tournament.

    This is a sample:

  • Here is a picture of a repeater that I use for my site:

  • This is somewhat involved, but assuming you have a player post for every player and a post for tracking the scores for each game, I would do the following:

    Create a taxonomy for the games. Ex.: Summer Tournament 2018.
    Create a field group with a number field for each game. So, if there are 16 games, there will be 16 boxes. Set your rules to have these appear where the Post Type is Player (or whatever your CPT is for players).

    Create a repeater with two fields: a post object field (players) and a number field. This should appear in whatever post or page you are using to keep track of a given game. The post object field will link the game to the player. Set your rules to appear where Post Type is (whatever post you are tracking the scores for each game) and the Taxonomy is (whatever you call your tournament). This is where you will track the scores for each player for a given game.

    Create a post for each of the summer games.

    The update field function will involve:
    Running a query to get the post ids for all the summer games.
    An outside loop of all the summer games, and an inside loop of the repeater with the scores for each game.
    Now you can grab the post id of the player and update the box corresponding to the game in the players profile.

    Now you can loop through each player and show their points on a separate page.

  • Are you trying to total the points for each game that a player scored points and then post the player’s total points on a single page?

  • One option would be to create a front-end form and just include that one field in the form:

    The documentation is here: Front end form

  • This question is hard to read without using the ‘code’ tags. Can you add these to any text in this post that you want to be read as code?

  • Yes, here’s an example:

    The code below adds the roster for a team based on certain criteria.

    function add_away_rosters_select($field){
    		
    		$sports_cat = array('boys-basketball','girls-basketball','boys-hockey','girls-hockey','baseball','softball','boys-lacrosse','girls-lacrosse','boys-tennis','girls-tennis');
    
    		$cat = get_the_category();
    		$sport = $cat[0]->slug;
    
    		$field['choices'] = array();
    		
    		if( in_array($sport,$sports_cat) ){
    
    		$away = get_field('away_team_2')->ID;
    
    		$args_1['post_type'] = 'roster';
    		$args_1['post_status'] = 'publish';
    		$args_1['order_by'] = 'title';
    		$args_1['order'] = 'ASC';
    		$args_1['meta_key'] = 'school_team';
    		$args_1['meta_value'] = $away;
    		$args_1['category_name'] = $sport;
    		$args_1['posts_per_page'] = -1;
    
    		$away_players = get_posts($args_1);
    
    		$away_roster = array();
    	
    		for($i = 0; $i < count($away_players); $i++){
    		
    			$away_player = get_field('last_name',$away_players[$i]->ID).", ".get_field('first_name',$away_players[$i]->ID);	
    			$away_player_ID = $away_players[$i]->ID;
    			$away_roster[$away_player_ID] = $away_player;	
    	
    		}
    
    		asort($away_roster);
    
                
                $field['choices'] = $away_roster;
                
            
    
    }
    
    		return $field;
    
    }
    
    // changes the choices to players from the away rosters
    
    add_filter('acf/load_field/key=field_58dadbb26c60a', 'add_away_rosters_select');
  • You have to add this to your query:

    So if you were trying to look for houses with the following criteria:
    CPT: houses
    Country: United States
    City: Los Angeles
    Beach: Manhattan

    I don’t know what your taxonomy slugs are, but insert them own below:

    $args = array(
    	'post_type' => 'houses',
    	'tax_query' => array(
    		'relation' => 'AND',
    		array(
    			'taxonomy' => 'country',
    			'field'    => 'name',
    			'terms'    => 'United States',
    		),
    		array(
    			'taxonomy' => 'city',
    			'field'    => 'name',
    			'terms'    => 'Los Angeles',
    		),
    		array(
    			'taxonomy' => 'beach',
    			'field'    => 'name',
    			'terms'    => 'Manhattan',
    		),
    	),
    );
Viewing 25 posts - 26 through 50 (of 69 total)