Support

Account

Forum Replies Created

  • @elliot No worries! Going to do some debugging tonight. Thanks for all your help and once again thank you for the awesome plugin. It is THE plugin that turns WordPress into a “true” CMS!

  • Hi @elliot,

    Thanks for this! That was really helpful and makes complete sense now. One issue I’m running into though, is the website begins to hang when you query more than three types. Do you know of any reason why that could be?

  • So are you saying this would work like this, @elliot?

    if( isset($_GET['foo']) ) {						
    
    $foo = explode('|', $_GET['foo']);		
    
    $meta_query[] = array(
    'key'		=> 'foo',
    'value' => '"' . $foo . '"',
    'compare'	=> 'LIKE',
    );
    }
  • @elliot Do you think this has anything to do with the serialized data the Checkbox Field outputs?

    Some of my books are assigned to multiple Book Types, like so:

    Book Title: Mums and Babies
    Book Type:

    • Women
    • Babies
    • Children

    Wondering if this is what’s causing the issue.

    This is where I’m at currently:

    add_action('pre_get_posts', 'my_pre_get_posts');
     
    function my_pre_get_posts( $query ) {
        if( is_admin() ) { return; }
     
        $meta_query = $query->get('meta_query'); // get original meta query
            
            if( isset($_GET['type']) ) {                        
            
            $type = '"' . $_GET['type'] . '"';      
    
            $meta_query[] = array(
                'key'       => 'type',
                'value'     => $type,
                'compare'   => 'LIKE',
            );
        }
        $query->set('meta_query', $meta_query); // update the meta query args
        return; // always return
    }

    Works with one value, but not multiple values (.com/?type=women,babies):

  • Had a similar problem early on. But the most recent update (4.3.3) seemed to resolve the issue.

  • Ok, false alarm. The code above was wrong. @elliot Some people over on the Stack Exchange forum are saying I shouldn’t be using a LIKE compare, and an IN instead when using arrays.

    Not sure which is right. But when I try to use an IN compare, I get a blank page when querying my posts.

    add_action('pre_get_posts', 'my_pre_get_posts');
    function my_pre_get_posts( $query ) {
    	if( is_admin() ) {
    		return;
    	}
    	$meta_query = $query->get('meta_query');
            if( !empty($_GET['type']) ) {				
            	$type = explode('|', $_GET['type']);	
    
    	    	$meta_query[] = array(							
                    'key'		=> 'type',
                    'value'		=> $type,
                    'compare'	=> 'IN',
                );
            }
    	$query->set('meta_query', $meta_query);
    	return;	// always return
    }
    
  • @elliot *Exhale* I feel to cry! After a whole day of staring at my functions.php, I think I may have finally cracked it!

    add_action('pre_get_posts', 'my_pre_get_posts');
     
    function my_pre_get_posts( $query ) {
    	if( is_admin() ) {
    		return;
    	}
     
    	$book_format = $query->get('meta_query');
     
            if( !empty($_GET['type']) ) {
            
    	    	$book_format[] = array(
                    'key'		=> 'type',
                    'value'		=> $_GET['type'],
                    'compare'	=> 'LIKE',
                );
            }
     
    	$query->set('meta_query', $book_format);
     
    	return;
    }

    Now when I append this to my url:

    dev.com/books?=home

    it displays an archive of all my books with the ‘type’ of ‘home’. This is fantastic!

    The only problem I’m having now is, separating these in the url with the ‘|’ character doesn’t seem to yield any results. Any idea why that might be happening, or is that normal?

  • @elliot Shouldn’t exploding and dumping my $_GET param return my seven checkbox values for the custom field ‘type’? When I do var_dump($wp_query->query_vars); it prints an array with 62 items. 😐

    Sorry if I’ve created a new thread entirely. I can’t seem to find the one you’re referencing.

  • OK, so I’m using an array for my checkboxes, and am using the pipe ‘|’ character instead of commas.

    Now, when I manually add my custom fields and separate them in the url like so:

    dev.com/slug?=field1|field2|field3

    this checks the appropriate checkboxes, but doesn’t return the filtered post results. Is there a different method, when using checkboxes?

  • @elliot Thanks for clearing that up for me.

  • Sorry for the late reply, I thought I had email notifications set up for this post.

    So the loop is working, but because I’m doing have_rows('wash') it’s only looping through my ‘wash’ rows. I would like it to loop through every single repeater row, of which I have 4 (wash, tumble, iron and dry).

    I can achieve this by doing 4 while loops, but figured there might be a more elegant solution out there that uses 1 while loop and jumps through my rows.

  • @elliot Simple is always better! Thanks once again, Elliot!

    I had to throw in a conditional argument, though, as the ‘max’ value isn’t always present.

    if( get_sub_field('to') == true ) {
    echo '<p>Min: ' . $min . 'mm (US' . $conversion[ $min ] . ') &ndash; ' . $max . 'mm (US' . $conversion[ $max ] . ')</p>'; }
    
    else {
    echo '<p>Min-Max: ' . $min . 'mm (US' . $conversion[ $min ] . ')</p>'; }
    

    One question I had is how are you pulling the $min variable in $conversion[ $min ]? Or is that simply just grabbing the value from my sub field, matching it in the array and pumping out its associated value?

  • @elliot Yeah, that’s the problem. Can’t work out how to retrieve $min/$max from $uk and $us separately. I’m so close, will bundling them both into a variable help?

  • I’m not sure there’s such a thing in Advanced Custom Fields. Anyone?

  • @elliot Of course, ‘mix’ can be called upon with get_sub_field_object, and is my select field! Thanks for jogging my tired brain.

  • I was dreading someone would point me to my database and assumed it would probably be the sure-fire way of doing this.

    Oh well, at least I know those field names will be gone for good if I do it via the phpMyAdmin panel.

    Thanks again!

  • @elliot I still can’t wrap my head around how to do this. Do I put the get_sub_field_object inside the have_rows while loop like this:

    <?php if( have_rows('blend') ): ?>
     
    	<ul>
     
    	<?php
    		$select = get_sub_field_object('blend');
    		$value = the_sub_field('mix');
    		$myvariable = $select['choices'][ $value ];
    
    		while( have_rows('blend') ): the_row();
    	?>
     
    		<li>
    		    <p><?php echo $myvariable; ?></p>
    		</li>
     
    	<?php endwhile; ?>
     
    	</ul>
     
    <?php endif; ?>

    This is returning en empty unordered list. Not sure if this is a result of working late, or I’m just missing the concept completely.

  • @elliot No worries Elliot! Would love to see a feature like that make a future version. Looking forward to ACF4!

  • Thanks, I’ll give that plugin a try!

  • Hi @elliot, first and foremost I’d just like to once again, thank you for making the most badass WordPress plugin I’ve ever used – ACF never ceases to amaze me!

    When you say create a field group, do you mean like this?

    field

    That’s still a pretty arduous process to get those items in there. I’m all for making things a tad easier on the backend.

    Any suggestions are welcome.

Viewing 20 posts - 1 through 20 (of 20 total)