Support

Account

Forum Replies Created

  • Hi @vitalunfolding

    Haven’t had a chance to replicate the issue above but as an initial measure try changing array($selectags) to just $selectags in your tags__in parameter. If ACF is already returning an array of tag IDs (which is then stored as such in you $selectags variable) then you shouldn’t need to warp it in another array.

    Hope that helps-if not, let me know if not and I’ll try and replicate the issue

    Cheers

  • From the looks of that code you’re not actually calling any ACF functions at all? For example, if your images are set within a repeater field then you should be using get_sub_field() to grab either the image object, Image ID or Image URL. I would recommend setting your image field within your repeater to use image object as that gives you the most flexibility.

    If it was me, I would do the following. I’ve assumed that the code to initialise and stop the repeater come before and after this chunk of code). I am also running under the assumption that you have set your image field to use the image object and that you have set an image thumbnail size in your functions.php file e.g. add_image_size( ‘my-thumbnail’, 240, 240, true );

    <li>
    <?php
       $image - get_sub_field('my_image_sub_field_name');
       echo '<img src="'.$image['sizes']['my-thumbnail'].'" />';
    ?>
    
    <div class="project-description">
       <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
       <p class="meta-info"><?php echo get_the_term_list( $post->ID, 'locations', '', ', ', '' ); ?></p>
       <a href="<?php the_permalink(); ?>" class="et-zoom"><?php esc_html_e( 'Read more', 'Vertex' ); ?></a>
    </div>
    
    </li>
  • Hi @lewmaster

    So if I’ve understood your issue correctly you’re trying to have a loop of posts which will only contain items where the ID of the logged in user matches the 1 or more users selected within the custom field you have setup? If that’s correct the code below should get you going in the right direction. Have commented inline and done some basic testing though you’ll need to adapt it to your needs. Hope it helps!

    <?php 
    //first let's check to makes sure the user is logged in
    if ( is_user_logged_in() ) : 
    
    //We set up our $user_ID global variable
    global $user_ID; 
    //populate above global
    get_currentuserinfo(); 
    
    //Create a set of arguments for our query
    $args = array(
    	'post_type'=> 'post',
    	'meta_query' => array(
    		array(
    			'key' => 'product_vendor_name', // name of custom field
    			'value' => serialize(strval($user_ID)), // matches post ID exactly e.g. "123", not just 123. This prevents a match for "1234"
    			'compare' => 'LIKE'
    		)
    	)
    );
    
    //Then run our query
    $myposts = new WP_Query($args);
    
    if ($myposts->have_posts()) : while ($myposts->have_posts()) : $myposts->the_post(); ?>
    
    <!-- Do your stuff here for the display of each post-->
    
    <?php 
    endwhile; //end our loop
    
    else: ?>
    
    	<p>no matching posts</p>
    
    <?php endif;
    
    // IMPORTANT - reset the $post object so the rest of the page works correctly
    wp_reset_postdata();  ?>
    								
    
    <?php 
    // If the user is not logged in provide an alternative display or message
    else :  ?>
    
    	<p>Not logged in message</p>
    	
    <?php endif; ?>
    
  • Hi @freshyill

    Something like the below should work for you:

    <?php 
    $count = 0;
    while( has_sub_field("content") ) : 
    
        if(get_row_layout() == "page_break") :
    	
            if(get_sub_field('break_here')){
               $count++;	
               echo $count;
            }
          
        endif;
          
    endwhile; ?>
    
  • Sorry – just realised that should have been:

    if (omd_table_filters === true) {
        my scripting goes here...
    }

    Another thing would be to maybe use == instead of === as the former checks for equality after doing any necessary type conversion.

    Finally do you have a fallback in the event that the field returns false? Is there any scripting that relies on the variable you set returning true that’s causing things to break?

  • Hi @Exelmans Graphics

    The true/false field will either output (unsurprisingly!) true or false.

    If you want your conditional to work then you should perhaps change it to

    if (omd_table_filters === false) {
        my scripting goes here...
    }

    That should work – shout if not

  • Hi @Exelmans Graphics

    I think your issue lies within these lines of code:

    <?php if ( get_sub_field("chart") ) : ?>
    											<?php foreach ( get_sub_field("chart") as $p ) : ?>
    <?php echo get_permalink($p->ID); ?>
    												<?php if( get_field( 'highcharts_beschrijving_van_de_grafiek', $p->ID) ): ?>
    												<div class="description"><?php the_field('highcharts_beschrijving_van_de_grafiek', $p->ID) ?></div>
    												<?php endif; ?>

    The first line is OK (testing to see if your ‘chart’ custom field exists) but the line after is a foreach which makes no sense in this context as the post object in your chart field is a single value.

    If you want to get the data associated with another post using the post object field simply do something like the following:

    <?php if ( get_sub_field("chart") ) : 
    
    	$p = get_sub_field("chart");
    	// Variable now stores the post object for the post chosen by the user
    	
    	//You can now do stuff with that post e.g.
    	$my_other_post = get_field( 'highcharts_beschrijving_van_de_grafiek', $p->ID);
    	
    	//This is example only - I have no idea what this field is or does
    	if($my_other_post){
    		echo $my_other_post;
    	}
    
    endif;// End check for chart field
    ?>
  • Hi @Excelmans Graphics

    If you always want a text block before any other flex content could you not just create a separate textarea/WYSIWYG and place it before your flex content (on the front end – you could always place it before the flex field in admin too to ensure it makes more sense to your client)? That way you always know it’s going to appear before any content your client adds.

    Not sure I can see the benefit to be able to lock content position for this use case – I guess it might be useful in cases where a certain content type needs to appear at a particular point in a loop e.g. every fifth item) but I think that’s possibly too edge to be worth baking in. Elliot might have other ideas!

  • Hi VBK

    Can you post up the code you are using to display the relationship field data?

    Remember that if you are setting up postdata in your loop then you MUST reset post data at the end of your loop in order for the rest of the page to display correctly (use wp_reset_postdata() after your endforeach)

    Please refer to the first loop example here:

    http://www.advancedcustomfields.com/resources/field-types/relationship/

    If you post up the code it should be easier to see where you’re going wrong.

    Thanks

  • Hi Trestian

    As far as I’m aware there’s no way to natively query taxonomies by custom meta (yet – think this is being mooted for inclusion in core – http://make.wordpress.org/core/2013/07/28/potential-roadmap-for-taxonomy-meta-and-post-relationships/)

    So, you could cook up some SQL based query but they’re not really something I’m much cop at so an alternative would be to get the id for the location term you are interested in finding vendors for and then looping through all your vendors, matching any with a location that is the same as your search location. You could check the matches into an array then iterate over that to display them.

    The code below isn’t tested or anything – it’s really just to get you headed in the right direction. I should also point out that it’s a bit of a clunky way round the problem, particularly if you have loads of vendors – there may well be a much simpler way to do this I’m not aware of. However it should do the trick.

    <?php
    
    $location_term = get_term( 'london', 'location' ); // Get term object for your chosen location
    
    $vendors = get_terms('vendors'); //Get all terms in vendors
    
    $matching_vendors = array(); // Create blank array for storing matching vendors
    
    foreach ($vendors as $vendor){ //Loop through all vendors
    	
    	$vendor_location = get_field('vendor_location', $vendor->term_id);//Get term object for the location associated with this vendor.  Please note that off the top of my head I can't recall the object structure that is returned.  I think it might be the same as the regular get_term object in which case the below should be correct
    	
    	if($vendor_location){ //Just check this variable exists
    	
    		if($vendor_location->term_id == $location_term->term_id){ // If the vendor location ID matches the ID for the location you are interested in...
    			
    			$matching_vendors[] = $vendor;//Add this vendor term object to you array
    		
    		}
    	
    	}
    
    }
    
    // You can then do what you like with regard to your matched vendors:
    
    if($matching_vendors){
    
    	foreach($matching_vendors as $vendor ){
    	
    		// Do stuff to list out your matched vendors
    	
    	}
    
    }
    
    ?>
  • Hi Intrepidrealist

    Your code seems a bit overly complex for what you’re trying to achieve. Before I get into a solution based on your current approach I would urge you to check out the repeater field or flexible content field add-ons that Elliot has put together. These are paid for additions to ACF but worth every penny and would make this sort of thing an absolute breeze compared to using custom post types for something like slides on a slider. If you are create a site for a client they will thank you!

    If you can’t or won’t go for these options then your code could be simplified quite a bit. Please see the stripped down example below. The biggest issue I could see is that you mention you have a radio button field but in your code you are not comparing your field against a proper value in your if statements. Please see the inline comments for more info. It’s not production code but hopefully it will give you a nod in the right direction

    <?php 
    //Instead of the meta query in your arguments just call for all slide posts - you can add ordering here if you want though
    $args = array( 'post_type' => 'slide', 'posts_per_page' => -1, ); 
    $loop = new WP_Query( $args ); 
    
    /*Just as a bit of good practice, if you call your if have_posts conditional before all slider content in the event 
    that there are no slides the whole slider will not show as opposed to showing an empty slider with no content*/
    
    if($loop->have_posts()) :  ?>
    
    <div class="flexslider">
    	  <ul class="slides">
    	  
    	  <?php while ($loop->have_posts()) : $loop->the_post(); // We then start looping through the slides ?>
    			
    			
    			<?php if ( get_field('slide_image') !=false) { 
    			
    			/* Here's where you problems start I think.  
    			Your radio field should have at least a couple of values e.g. you could 
    			have image_slide and video_slide as your two values on your radio field
    			Your if statement above would then look like this:
    			
    			if ( get_field('slide_image') == 'image_slide') {
    			
    			*/
    			?>
    		
    			<li>
    				<!-- Your slide content goes here -->
    			</li>
    			
    			<?php 
    			/* 
    			Your version of the code below looked a bit broken - this you would have got a syntax error as your else if statement was malformed
    			The version below copies the example I gave you above but checks to see if the slide is a video slide
    			*/
    			} elseif ( get_field('static_slide_image') == false) { ?>
    				
    			<li>
    				<!-- Your slide content goes here -->
    			</li>
    			<?php  } ?>
    			
    			<?php //close off loop
    			endwhile; ?>
    			
    		</ul>
    </div>
    		 
    <?php  
    endif;
    wp_reset_query();
    ?>
Viewing 11 posts - 1 through 11 (of 11 total)