Support

Account

Forum Replies Created

  • Well, I have another site I’m trying to use this sorting feature on, but for some reason it’s just not working this time, and I’m not sure why. Hoping someone here can help me figure it out.

    Everything displays, except that the <h2> gets added before each item (meaning, for instance, that I get:

    ALABAMA

    • Property Name

    ARKANSAS

    • Property Name

    FLORIDA

    • Property Name

    FLORIDA

    • Property Name

    And it needs to show those last two as

    FLORIDA

    • Property Name
    • Property Name

    Here’s my code:

    $props_args = array(
       'post_type' => 'properties',
       'posts_per_page' => -1,
       'post_status' => 'publish',
       'meta_query' => array(
          'state_clause' => array(
             'key' => 'which_state',
             'compare' => 'EXISTS',
          ),
       ),
       'orderby' => array(
          'state_clause' => 'ASC',
          'title' => 'ASC'
       ),
       'order' => 'DESC',
    );
    
    $props_query = new WP_Query($props_args);
    if ($props_query->have_posts()) { ?>
    
    <main class="container">
       <div class="row">
    
          <?php // variables to hold values from previous post
          $last_state = '';
    
          while ($props_query->have_posts()) {
             $props_query->the_post();
    
             // get state and compare it to the previous post
             $this_state = get_field('which_state');
    
             if ($this_state != $last_state) {
    
                // the state has changed
                if ($last_state != '') {
                   // close the post UL, city DIV, and state DIV that we'll open next
                   // this will be skipped if this is the first post
                   // because $last_state will be empty
                   echo '</tbody></table><!-- list --></div><!-- state -->';
                }
                echo '<div class="state"><h2>'.$this_state.'</h2>';
             } // end if new state
    
             // Vars
             $marker = get_field('address');
             $address = explode( "," , $marker['address']);
             $logo = get_field('property_logo'); ?>
    
             <tr>
                <td class="gold-border"></td>
                <td class="first">
                   <a class="link" href="<?php the_permalink(); ?>" target="_blank"><img src="<?php echo $logo; ?>" class="style-svg" alt="<?php the_title(); ?>"></a>
                </td>
                <td>
                   <?php echo $address[0].''; //street number ?><br />
                   <?php echo $address[1].','.$address[2]; //city, state + zip ?>
                </td>
             </tr>
          <?php  } // end while have posts
    
          // we need to close the last set of elements that were opened
          echo '</tbody></table><!-- list --></div><!-- state -->'; ?>
    
       </div>
    </main>
    
    <?php } // end if have_posts
    
    wp_reset_query();
  • AHA! Adding the reset_rows() to the one with the count seems to have fixed it! Thank you very much!

  • Hmmm…except that the if( get_field(‘home_or_on_tour’, ‘option’) == ‘tour’ ): isn’t the repeater. I’m checking first to see if “tour” was selected in an option dropdown. The repeater appears conditionally, depending on which item is selected there. However, I’d never seen the reset_rows code, so I will give that a try as soon as I’m back at my computer. THANK YOU!!

  • Note: The reason I’m thinking this still falls under ACF is that the date field is what I’m dealing with.

  • Well, not really. If I just wanted the first one to be “active”, that would work fine. But I want the *next* one to be active.So, let’s say the first event is on September 23rd, the next on October 21st, but today is September 25th. I don’t want the September 23rd one to be active anymore. I want the October 21st one to be active. See what I mean?

  • You were actually wonderfully helpful. You helped me realize that I needed to just add another meta query field for the different series’. Now I’ve got it working perfectly! Thank you!

  • It’s getting the posts. I’m just not having any luck getting the sub-headings with the performance dates that are in that sub-heading category (cantata series, masterworks series). Right now I get the sub-heading above each date, instead of sorted under the sub-heading.

  • Sooooo…y’all were super helpful before and I was able to apply this filtering to another website as well. All was going swimmingly until the client asked for one more level of sorting, and I’m tearing my hair out trying to figure this out.

    So, this is for a choral group. They’re wanting to display all their past seasons, sorted by year/season, and then by performance date (performances are actually individual products in WooCommerce). Sorting by the ACF meta fields is going fine. But within each year, they also want to break it out to sorting all the concerts assigned the ‘cantata-series’ product category, and the ‘masterworks-series’ product category. So, a typical listing would look something like:

    2017-2018 SEASON
    Cantata Series
    * Concert Date 1
    * Concert Date 2
    Masterworks Series
    * Concert Date 1
    * Concert Date 2

    2016-2017 SEASON
    Cantata Series
    * Concert Date 1
    * Concert Date 2
    Masterworks Series
    * Concert Date 1
    * Concert Date 2

    etc. etc. etc.

    I was doing fine when it was just sorting by season and then by date. But adding in sorting by category is just throwing me. I can get it to display the correct series before each and every date it applies to, but that’s not right.

    Here’s my code right now (not working)

    $season_args = array(
    		'numberposts' => -1,
    		'post_type' => 'product',
    		'product_cat' => 'past, cantata-series, masterworks-series',
    		'meta_query' => array(
    			'season_clause' => array(
    				'key' => 'select_season',
    				'compare' => 'EXISTS',
    			),
    			'date_clause' => array(
    				'key' => 'date',
    				'compare' => 'EXISTS',
    			)
    		),
    		'orderby' => array(
    			'season_clause' => 'ASC',
    			'date_clause' => 'ASC'
    		)
    	);
    	
    	$the_query = new WP_Query($season_args);
    	
    	if ($the_query->have_posts()) {
    		// variables to hold values from previous post
    		$last_season = '';
    		$last_date = '';
    		
    		while ($the_query->have_posts()) {
    			$the_query->the_post();
    			
    			// get season and compare it to the previous post
    			$this_season = get_field('select_season');
    			
    			if ($this_season != $last_season) {
    				// the season has changed
    				if ($last_season != '') {
    					// close the post UL, season DIV, and season DIV that we'll open next
    					// this will be skipped if this is the first post
    					// because $last_season will be empty
    					echo '</div><!-- .season -->';
    				} ?>
    				
    				<div class="season">
    					<h2><?php echo $this_season->post_title; ?></h2>
    				
    				<?php  // clear $last_season
    				$last_season = '';
    				// set $last_season to $this_season
    				$last_season = $this_season; ?>
    				
    				<?php if ( has_term( 'cantata-series', 'product_cat' ) ) { ?>
    						<h3>Cantata Series</h3>
    						
    				<?php } 
    			} // end if new season
    			
    			// get the date and compare to previous post
    			$this_date = get_field('date', false, false);
    			$this_date = new DateTime($this_date); ?>
    			
    				
    							<?php if ( has_term( 'cantata-series', 'product_cat' ) ) { ?>
    							<li><?php echo $this_date->format('M j Y'); ?> - <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php } ?>
    		<?php } // end while have posts
    	} // end if have_posts
    
    wp_reset_query();

    Thanks in advance.

    ~Laura

  • This is my current code:

    if( have_rows('cast') ):
       while ( have_rows('cast') ) :
          the_row();
    
             $cast_object = get_sub_field('actor_actress');
             if ( $cast_object) {
                $terms = get_object_terms($cast_object->ID, 'cast_crew_category', array('fields' => 'ids'));
                $thumbid = get_post_thumbnail_id($cast_object->ID);
                $thumb = wp_get_attachment_image_src( $thumbid, 'thumbnail' );
                $url = $thumb['0'];
                $role = get_sub_field('role');
    
                if (in_array('83', $terms)) {
                   echo $role; ?>
                   <a href="<?php echo get_permalink($cast_object->ID); ?>" rel="lightbox" data-lightbox-type="iframe"><img src="<?php echo $url; ?>" width="100%" height="auto"></a>
                   <a href="<?php echo get_permalink($cast_object->ID); ?>" rel="lightbox" data-lightbox-type="iframe"><?php echo $cast_object->post_title; ?></a>
                <?php }
             }
       endwhile;
    endif;
  • This is what I get now:

    Fatal error: Call to undefined function get_object_terms()

  • So, after having a 2nd pair of eyes take a look, I realized it was a dumb error on my own part. In my attempt to be smart about when and where I loaded scripts, I had not set the maps script to load on this archive page. D’OH! It was loading fine for the other pages I needed the maps on, but I had built the site several months ago and just didn’t even remember this, and glancing through things it didn’t “register” in my brain either. It now works great {hangs face in abject shame}

  • You could be right. And I apologize if I was getting at all snarky. It wasn’t my intent. The status thing at the top said “Not Read”, so that’s what I was going by.

    I’ve looked through both of those links before posting here. Perhaps the issue is simply that the map itself isn’t appearing? I’ve got markers being generated. At the *very* bottom of the first link you provide it says to trigger the resize event using the following code:

    // popup is shown and map is not visible
    google.maps.event.trigger(map, 'resize');

    But doesn’t explain where to put the code. Does it go in functions or does it go in the map.js file? And where in either one. I tried putting it at the end of the .js file, and it broke things. Do you have any ideas what they mean by that?

    And I do truly appreciate the user help provided here. SO much. I apologize again if I sounded at all ungrateful.

  • Bump? How has this not even been read in more than 24 hours?

  • I’m getting a “Notice: Undefined variable: value” using this script. Any ideas how to solve this?

    Note: If I remove “, $value”, it outputs the marker divs, but the map doesn’t appear.

  • D’OH!!! A missing ‘S’!! That did it! Thank you! Can’t believe I didn’t see it either. I had to look HARD for that one! LOL

  • I was even able to add in another sorting parameter (country) seeing how this worked. Thank you loads!

  • BLAMMO!!!! Thanks so much, man!!!

  • facebook_group_name is a simple text field.

    The most recent code you provided displays zip, zero, zilch, nada.

  • And how might one modify the OP code to output ALL states separately, with associated Cities under each state like:

    ALABAMA
    -city 1
    -city 2
    -city 3

    TENNESSEE
    -city 1
    -city 2
    -city 3

    VIRGINIA
    -city 1
    -city 2
    -city 3

  • My apologies for taking awhile to get back to this.

    So, the first part works fine. But the 2nd section seems to be causing the page to never fully load. I’m not sure why.

Viewing 25 posts - 1 through 25 (of 86 total)