Support

Account

Forum Replies Created

  • This is what I have figured out so far…. but I can’t seem to get the seed to work with the session and keeping random working with pagination.

    Not sure if this is a Genesis issue at this point, my code, or WordPress.

    global $post;
      
    $query = new WP_Query( 
      array( 
        'post_type' => 'artist', 
        'posts_per_page' => -1,
        'fields' => 'ids',
        'meta_query' => array(
        	array(
            	'key' => 'artist_gallery'
                )
    		  )
            ) 
          );
            $seed = $_SESSION['seed'];
            if (empty($seed)) {
              $seed = rand();
              $_SESSION['seed'] = $seed;
            }
            $args = array( 
                'post_type' => 'attachment', 
                'post_status' => 'inherit',
                'orderby' => 'RAND(' . $seed . ')',
                'post_mime_type' => 'image', 
                'posts_per_page' => 30, 
                'post_parent__in' => $query->posts, 
                'order' => 'DESC' 
                );
      
     	global $wp_query;
        $wp_query = new WP_Query( $args ); 
    
        if ( have_posts() ) : 
            while ( have_posts() ) : the_post(); 
    			$image_attachment = get_attachment_link( get_the_ID() );
    			$img_src = wp_get_attachment_image_src( get_the_ID(), 'medium');
    			$alt = get_the_title();
    echo '	
    			<div class="col-md-4"> 
    				<a href='. $image_attachment .'>
    					<img src="'. $img_src[0] .'" alt="'. $alt .'" />
    				</a>
    				<p>'. $image["caption"] .'</p>
    			</div>
    ';
    	endwhile;
    	do_action( 'genesis_after_endwhile' );
    endif;				
    
    // Restore original Post Data
    	wp_reset_postdata();
    
  • Has anyone figured out how to do this dynamically for multiple keys and values. I tried something like this (below) but I can’t get it to work.

    I have quite a few fields I need to be filtering for. I can get each field to work one at a time, but the second I try to do more than one, I see only field being filtered when i run “echo $GLOBALS[‘wp_query’]->request;”

    Any help would be HUGE. I have been stuck on this for quite some time! Thank you in advance.

    
    		add_filter('posts_where', 'my_posts_where');
    		function my_posts_where( $where ) {
    			/* if( isset($_GET['feelings_$_feeling']) ) {
    			$where = str_replace("meta_key = 'feelings_$", "meta_key LIKE 'feelings_%", $where);
    			return $where;
    			} */
    
    			$rootkeys[] = $_GET;
    			global $wpdb; //TESTING
    			foreach($rootkeys as $rootkey) {
    				foreach($rootkey as $key => $value) {
    					$partialkey = explode("$",$key);
    					$keya = $partialkey[0];
    					$keyb = 'meta_key = \''.$keya.'$';
    					$keyc = 'meta_key LIKE \''.$keya.'%'; //this = was LIKE, should it be?
    			// $where = str_replace($keyb, $keyc, $where);
    			$where = str_replace($keyb, $keyc, $wpdb->remove_placeholder_escape($where));
    			}
    			}
    			return $where;
    
    		}	
    
  • Ok, got it…. finally…

    
    	$rootkeys[] = $_GET;
    	foreach($rootkeys as $rootkey) {
    		foreach($rootkey as $key => $value) {
    			$partialkey = explode("$",$key);
    			$keya = $partialkey[0];
    			$keyb = 'meta_key = \''.$keya.'$';
    			$keyc = 'meta_key LIKE \''.$keya.'%';
    	$where = str_replace($keyb, $keyc, $where);
    	}
    	}
    	return $where;
    
    
  • Ok, so I got this far…..
    $keya outputs feelings_$ and medical_use_$ which is CORRECT….. But… this still doesn’t work.

    
    	$rootkeys[] = $_GET;
    	foreach($rootkeys as $rootkey) {
    		foreach($rootkey as $key => $value) {
    			$partialkey = explode("$",$key);
    			$keya = $partialkey[0].'$';
    	$where = str_replace("meta_key = $keya", "meta_key LIKE 'feelings_%", $where);
    	}
    	}
    	return $where;
    
    
  • I am trying to figure out how I can just use $_get, and pull the array.

    Using this

    // If you have the following URL :
    
    // http://www.example.com/test.php?a=10&b=plop
    
    // Then $_GET will contain :
    
    array
      'a' => string '10' (length=2)
      'b' => string 'plop' (length=4)

    From https://stackoverflow.com/questions/5415224/how-to-set-get-variable

    So, this should loop through each parameter and value in the URL.
    However; if I understand this filter, it is only pulling part of the value, and I can’t figure out what this is actually populating for $rootkey. I can’t figure out how to see that ECHO.

    	
    $rootkeys[] = $_GET;
    	foreach($rootkeys as $rootkey) {
    	$where = str_replace("meta_key = 'feelings_$", "meta_key LIKE 'feelings_%", $where);
    	
    	}
    	return $where;
    
  • Hey guys, I almost had it figured out. I don’t know why I didn’t think of just using a $GET. So as long as 1 filter is selected at a time, it now works. But the second that I select a filter, and a medical_use (url of something like ” strains?feelings_$_feeling=Euphoric&medical_use_$_medical=Seizures ”

    Does anyone have any idea how I can get this to work for any meta_query in the URL?

    
    add_filter('posts_where', 'my_posts_where');
    function my_posts_where( $where ) {
    	if( isset($_GET['feelings_$_feeling']) ) {
    	$where = str_replace("meta_key = 'feelings_$", "meta_key LIKE 'feelings_%", $where);
    	return $where;
    	}
    	
    	if( isset($_GET['medical_use_$_medical']) ) {
    	$where = str_replace("meta_key = 'medical_use_$", "meta_key LIKE 'medical_use_%", $where);
    	return $where;
    	}
    	
    	return $where;
    } 
    
  • Has anyone been able to do this with a hook as opposed to editing the acf plugin?
    How can I add this code in, and still allow for updates to ACF?

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