Support

Account

Home Forums Search Search Results for 'q'

Search Results for 'q'

reply

  • I was able to fix it!

    I changed my code to:

    <?php $args = array( 'posts_per_page' => -1, 'post_type' => 'siteinfo' );
                $myposts = get_posts( $args );
                foreach ( $myposts as $post ) : setup_postdata( $post ); 
                    $phone = get_field('phone_number'); ?>
    <div class="phone">
         <p><img class="phone-img" src="<?php bloginfo('template_directory'); ?>/images/phone.png" alt="<?php bloginfo('name'); ?>" /><span><?php echo $phone; ?></span></p>
    </div><!--end.phone-->
    <?php endforeach; 
    wp_reset_postdata();?>

    Thanks for your help!

  • Hi @mccawphoto

    The code:

    <?php $posts = get_posts(array(
                	'post_type' => 'siteinfo',
                    'posts_per_page' => -1
                  ));
    	$phone = get_field('phone_number');	  
    if ( $posts->have_posts() ) : while ( $posts->have_posts() ) : $posts->the_post();	

    Is not valid.

    Please read the get_posts documenation to understand how to loop over the posts.
    Perhaps you intended to use WP_Query instead? Please research this as well.

    Thanks
    E

  • Hi @johanngonzalez

    The above code does not ouput anything to HTML.
    Please echo any PHP value to HTML.
    <img src="<?php echo $image; ?>" />

    Thanks
    E

  • Hi @jarvis

    You can first get all the sectors by performing a get_postshttp://codex.wordpress.org/Template_Tags/get_posts

    Loop over these results, and for each sector display the title and link.

    To find the count of jobs in this sector will require another get_posts call for each sector.

    The post_object (multi-select) saves it’s data in the same format of a relationship field (serialized array of IDs), so you can follow this tutorial to perform a backwards query: http://www.advancedcustomfields.com/resources/tutorials/querying-relationship-fields/

    Thanks
    E

  • Hi Elliot, thank you for getting back to me.

    I’m using the Relationship field with Flexible Content to create a list of selected posts which is called Featured Posts:

    <?php
    while( has_sub_field( 'page_builder' ) ):
       if( get_row_layout() == 'featured_posts' ):
          get_template_part ( 'builder/featured', 'posts' );
       endif;
    endwhile;
    ?>

    The loop inside featured-posts.php looks like this:

    <?php 
    $featured_posts = get_sub_field( 'featured_post_add' );
       if( $featured_posts ):
          foreach( $featured_posts as $post ): ?>
    
             <article>
                ...
             </article>
    
    <?php
          endforeach;
          wp_reset_postdata();
    endif;
    ?>

    Everything works great.

    Now what i’m trying to do, is to output the exact same posts, added in this Relationship field, in a widget. I have created a widget file featured-posts-widget.php which i drag into the sideabr. The thing is that the posts are not showing up and the widget is blank, besides the title, no matter what type of loop or a query i use. The code among others i tried is:

    
    <?php
    global $post;
    $featured_posts_sidebar = get_field( 'featured_post_add' );
       if( $featured_posts_sidebar ):
          foreach( $featured_posts_sidebar as $post ): ?>
    
             <article>
                ...
             </article>
    
    <?php
          endforeach;
          wp_reset_postdata();
    endif;
    ?>

    In the widget i use get_field and not get_sub_field. Maybe using WP_Query and not the foreach loop would be a solution, but what parameters do i have to use?

    Can you point me to the right direction?

  • Hi! Just wanted to update you on this. I had a programmer look at it and apparently the issue was that the $posts global variable was being overridden.

    When I searched through the code, the only places I saw that variable mentioned was in the main WordPress files, the ACF plugin, and the Event Calendar plugin (which I tried disabling and didn’t make a difference). So I’m not sure exactly what was the culprit there, but once that variable name was changed, it worked fine.

    Here’s the code that ended up working in case anyone else has a similar issue:

    <?php $store_type_posts = (array) get_field('store-type'); ?>
    <?php foreach ($store_type_posts as $store_type_post): ?>
    <?php $store_type_logo_id = get_field('store-type-logo', $store_type_post->ID) ?>
    <?php if ($store_type_logo_id) : ?>
    <?php $image = wp_get_attachment_image_src($store_type_logo_id, 'Store_Logo'); ?>
    <?php $alt_text = get_the_title($store_type_logo_id); ?>
    <img src="<?php echo $image[0]; ?>" alt="<?php echo $alt_text; ?>" width="<?php echo $image[1]; ?>" height="<?php echo $image[2]; ?>" class="plain" />
    <?php endif ?>
    <?php endforeach ?>
  • Looks like you are missing the closing single quote on ‘artist’

  • I’ve tried that but had no luck the filed should just be gallery I believe,
    this is the other gallery that shows up on the page http://dev.rgbdesignuk.com/memorial/test-test/

     <h2>Gallery</h2>
                                
                                <?php if(get_field('gallery')):?>
                                    <?php foreach (get_field('gallery') as $gal ):?>
                                        <a class="fancybox" rel="gallery1" href="<?php echo $gal['url']?>" title="<?php echo $gal['caption'] ?>"><img src="<?php echo $gal['sizes']['thumbnail']?>" alt="" /></a>
                                    <?php endforeach ?>
                                <?php endif; ?>   
                                
                                <?php if( $the_galquery->have_posts() ): ?>
                          
                                  <?php while ( $the_galquery->have_posts() ) : $the_galquery->the_post(); ?>
                                  <a class="fancybox" rel="gallery1" href="<?php echo wp_get_attachment_url( get_the_ID()); ?>" ><?php echo wp_get_attachment_image( get_the_ID(), 'thumbnail'); ?></a>
                                  <?php endwhile; ?>
                                <?php endif; ?>
    
                                <?php if ( !(get_field('gallery')) && !($the_galquery->have_posts() ) ):?>
                                <p>No Gallery added</p>
                              <?php endif ?>
                                 <?php if ( is_user_logged_in() ): ?> 
                                    <form  style='clear:both' id="file-form" enctype="multipart/form-data" action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">
                                      <p>Add image to gallery</p>
                                      <p id="async-upload-wrap"><label for="async-upload">upload</label>
                                      <input type="file" id="async-upload" name="async-upload"> <input type="submit" value="Upload" name="html-upload"></p>
    
                                      <p><input type="hidden" name="post_id" id="post_id" value="<?php echo $post_id ?>" />
                                      <?php wp_nonce_field('client-file-upload'); ?>
                                      <input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>" /></p>
    
                                      <p><input type="submit" value="Save all changes" name="save" style="display: none;"></p>
                                    </form>
                                    
                                    <form  style='clear:both' id="embed-form" action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">
                                      <p>Add video to gallery</p>
                                      
                                      <label for="embed">You tube / vim url:</label>
                                      <textarea name="embed"></textarea>
                                      <input name='submit_video' type="submit" value="submit">
                                      <p>
                                        <input type="hidden" name="post_id" id="post_id" value="<?php echo $post_id ?>" />
                                      <?php wp_nonce_field('embed-form'); ?>
                                      <input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>" /></p>
                                    </form>
                                  <?php endif?>
                                </div>
  • Hi Elliot,

    I’ve fixed it. Interchange does indeed use ajax to switch out files and I think that’s why the acf values weren’t being loaded – because, as you correctly pointed out, wp didn’t know which post to pull them from.

    I added the page ID to the repeater code and it worked:

    <?php
    require($_SERVER['DOCUMENT_ROOT'].'/pwp/wp-load.php');
    ?>
    
    <div class="phone_email_holder">
    
    <p>LARGE TEMPLATE</p>
    
    	<?php if( have_rows('phone_numbers', 7) ): ?>
    			<?php while( have_rows('phone_numbers', 7) ): the_row(); ?>
     			<div class="contact_field_wrapper row">
    	        	<div class="phone_email_label info_label">
    	        		<?php echo get_sub_field('number_label', 7) ?>:
    	        	</div> 
    	        	<div class="phone_email_value">
    	        		<?php echo get_sub_field('tel_number', 7) ?>
    	        	</div>
    		    </div>
    		<?php endwhile; ?>
    	<?php endif; ?>
    	
    </div>

    However, it does have to include the wp-load file to work.

    Thanks for your help on this. I only recently discovered ACF and it’s bloody amazing. Good work!

    Thanks,
    Xav

  • Im not sure if i have done this right or not its on the following page surposed to be in the side bar http://dev.rgbdesignuk.com/memorial/test-test/

    but its not showing up please help

    <!--slider starts-->
                 <!-- Start Photo Slider -->
    <?php
    /*
    *  Create the Markup for a slider
    *  This example will create the Markup for Flexslider (http://www.woothemes.com/flexslider/)
    */
    $property_images = get_field('gallery');
    if( $property_images ) { ?>
    <div id="slider" class="flexslider">
      <ul class="slides">
        <?php foreach( $property_images as $property_image ): ?>
          <li>
            <img src="<?php echo $gallery_image['url']; ?>" alt="<?php echo $gallery_image['alt']; ?>" />
          </li>
        <?php endforeach; ?>
      </ul>
    </div>
    <?php
    
    /*
    *  The following code creates the thumbnail navigation
    */
    
    ?>
    <div id="carousel" class="flexslider">
      <ul class="slides">
        <?php foreach( $gallery_images as $gallery_image ): ?>
          <li>
            <img src="<?php echo $gallery_image['sizes']['thumbnail']; ?>" alt="<?php echo $gallery_image['alt']; ?>" />
          </li>
        <?php endforeach; ?>
      </ul>
    </div>
    <?php
    }else{
    ?><div id="single-gallery-image">
      <?php the_post_thumbnail('full'); ?>
    </div><?php
    
    ?>
    <?php } ?>
    <!-- End Photo Slider -->
    
    </div>
    
    <link rel="stylesheet" href="http://dev.rgbdesignuk.com/wp-content/themes/canvas-child/memorials/css/flexslider.css" type="text/css">
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script src="http://dev.rgbdesignuk.com/wp-content/themes/canvas-child/memorials/js/jquery.flexslider-min.js"></script>
    <script type="text/javascript">
      var $f = jQuery.noConflict(true);
        $f(window).load(function() {
          // The slider being synced must be initialized first
          $f('#carousel').flexslider({
          animation: "slide",
          controlNav: false,
          animationLoop: false,
          slideshow: false,
          itemWidth: 75,
          itemMargin: 5,
          asNavFor: '#slider'
          });
           
          $f('#slider').flexslider({
          animation: "slide",
          controlNav: false,
          animationLoop: false,
          slideshow: false,
          sync: "#carousel"
          });
        });
    </script> 
                 <!--slider ends-->
  • Sorry,
    The true solution

    <?php 
    	$posts = get_field('sidebar_widget');
    			$args = array(
    			'post_type' => 'sidebar-widget',
    			'name'=> ($posts->post_name), //get the value in array
    			);
    			$query = new WP_Query( $args );
    
    			// The Loop
    			?>													
    			<?php if($query->have_posts()) : ?>
    				<?php while($query->have_posts()) : ?>
    				<?php $query->the_post(); ?>
    					<?php include('widget/content-sidebar-widget.php'); ?>
    				<?php endwhile; ?>
    				<?php wp_reset_postdata(); ?>
    			<?php endif; ?>
    			
    
  • Here’s the code I created.

    https://github.com/theideabureau/acf-reusable-group-field

    This plugin works well and is very handy. However I’ve just run into one caveat – when using the Reusable Group Field within a Flexible Content Field you can only use it once per page.

    If you try and use a Reusable Group in more than one row it doesn’t seem to store a separate database entry for each instance of the group.

    This would be such a great feature to have as it would give ACF a really nice modular approach.

  • Yes, the page breaks after the navigation at the top of the page.

    Now I have this error showing up where the page breaks:

    “Fatal error: Call to a member function have_posts() on a non-object in /home/senroctech/public_html/wp-content/themes/Senroc/banner-cat.php on line 66”

    Here is my code where the page breaks:

    <?php $posts = get_posts(array(
                	'post_type' => 'siteinfo',
                    'posts_per_page' => -1
                  ));
    	$phone = get_field('phone_number');	  
    if ( $posts->have_posts() ) : while ( $posts->have_posts() ) : $posts->the_post();		  
    
    <div class="phone">
       <p><img class="phone-img" src="<?php bloginfo('template_directory'); ?>/images/phone.png" alt="<?php bloginfo('name'); ?>" /><span><?php echo $phone; ?></span></p>
    </div><!--end.phone-->
                
       <?php endwhile;  
    endif; ?>
  • Hahaha I’m a total moron!

    I had two test products called the same thing and I was testing the output on the wrong product… der 🙂

    Thanks for your help anyway 🙂

    a quick one, adding ‘die’ at the end of the debug stuff, what does that do exactly (and should I be adding that to all add_action functions in the future)?

  • Hi @QueenEve

    You can remove the if statement surrounding the the_field function, ACF api will be available within this action.

    It is most likely that ACF doesn’t haeva value for the field ‘test_field’, or ACF doesn’t know which post to load from.

    You can do some testing like so:

    <?php 
    
    echo '<pre>';
    	print_r(get_the_ID());
    echo '</pre>';
    echo '<pre>';
    	print_r(get_field('test_field'));
    echo '</pre>';
    die; ?>

    Please report the output

    Thanks
    E

  • Hi @augusto

    When any AJAX request is sent, you can view the response data like in the attachment bellow. It is important to see what the relationship field is returning.

    This will allow you to determine if the issue is in the PHP / JSON, or if the problem lies somewhere else such as JS.

    Thanks
    E

  • Hi @mccawphoto

    When you say But that made everything below the navigation disappear. do you mean that the page broke? This is most likely a PHP error.

    You can debug this error by turning on DEBUG_MODE in your wp-config.php file.

    You are posting too much code above for me to see any potential issues. Please reduce your code to the bare skeleton to determine why any errors are happening.

    Use a simple debugging technique like:

    <?php 
    
    echo '<pre>';
    	print_r($variable);
    echo '</pre>';
    die; ?>

    on each line to view variable data and see visually that your code made it to that line without breaking.

    Thanks
    E

  • Hi @Vasili

    Can you please elaborate more on the question? I don’t understand what you have and what you are trying to do.

    Perhaps some screenshots to show the data structure, and a better explanation of what you mean by:
    The thing is that i’m also trying to show the same posts, added with relationship field, inside a sidebar widget. As you understand this have no affect,

    Thanks
    E

  • Hi,

    I’m not sure how you went with this, but I am trying to add some ACF fields to the Single Products Page in Woocommerce. I was hoping to use the hooks that woocommerce provides to add the custom fields stuff, but I can’t seem to get the fields to output anything.

    in my functions.php I have added an action like so:

    // Add ACF Info to Product display page
    add_action( 'woocommerce_after_single_product_summary', "ACF_product_content", 10 );
    
    function ACF_product_content(){
      
      echo '<h2> ACF Content </h2>';
      
      if (function_exists('the_field')){
        echo '<p>Woohoo, the_field function exists! </p>';
    
        the_field('test_field');
    
      }
      
    }
    

    The h2 and the p are displayed, but the field itself doesn’t get rendered. Any thoughts?

    Cheers.

  • Still searching to do this with the gallery field add on… cannot make something work. Will be easier I guess with a repeater field.
    The difficulty I think is how to get the attachement id for each image as the gallery field call for all pictures $attachment_id = get_field('gallery');' not working. So I tried this:

    <?php
    /*
    *  Gallery
    */
    // url = $image[0];
    
    $images = get_field('gallery');
    $field = get_field_object('size-gallery');
    $value = get_field('size-gallery');
    $label = $field['choices'][ $value ];
     
    if( $images ): ?>
                    <?php foreach( $images as $image ): ?>
    				<?php $image2 = wp_get_attachment_image_src( $image['id'], $label ); ?>
    <li>
    			<a href="<?php echo $image2[0]; ?>" class="fancybox" rel="gallery" title=""><div class="miniature"><img src="<?php echo $image2[0]; ?>" /></div></a>
    		</li>
            
    	            <?php endforeach; ?>
    <?php endif; ?><!--FIN DE GALERIE PHOTOS -->

    The gallery works but the $label has no effect.

    Any idea would be great. I really need to make it works. Thanks

  • Hi @Xav

    including files or ‘partials’ is a common templating task which does not usually prove so dificult. There must be something else going on here.

    The require($_SERVER['DOCUMENT_ROOT'].'/pwp/wp-load.php'); code should never be included in a correct page template.

    I think the issue is that you are including them in a non PHP friendly way. How does Zurb’s data interchange work?

    Your origional code:

    <div data-interchange="[<?php echo get_stylesheet_directory_uri();?>/library/interchange/contact_details_small.php, (small)], [<?php echo get_stylesheet_directory_uri();?>/library/interchange/contact_details_default.php, (medium)], [<?php echo get_stylesheet_directory_uri();?>/library/interchange/contact_details_default.php, (large)]">
    </div>

    Shows that you place urls into a data attribute on a div. Have you checked the docs to see if these can be PHP files? If so, are they loaded via an ajax request? If so, how would WP know what $post to query for that file?

    Thanks
    E

  • Hi @ramesh

    This FAQ will help explain what is happening:
    http://www.advancedcustomfields.com/resources/faq/losing-data-save/

    Thanks
    E

  • 1. Repeater field with a text sub-field type and a true_false sub-field.

    2. this is a sub-field

    3. the content entered in the text field.

    4. Page B is a wordpress page which wont have any user content loaded from the standard wordpress CMS or any fields shown from ACS. The data from 1 row of the repeater on page A will auto populate on page B if the true_false checkbox is checked in that row.

    5. Page A is accessed from a link on the website. Page B will be accessed from a link on page A.

    6. The content in the subfields in the repeater will either post to page A or B depending on if the checkbox is checked. But all of the rows will always be managed from a “wordpress page” in the wordpress admin. I am using a rule to show if field group is equal to page A.

    Hopefully this clarified everything.

  • Ok so I went through that tutorial – bedrooms was already one of the fields I need to sort by, so I thought it would be easy – however, I am having a lot of trouble with this still.

    This is the code I put in my functions file:

    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
        
        
        // validate type
        if( empty($_GET['bedrooms']) )
        {
    	    return;
        }
        
        
        // get types as an array
        // - use explode to get an array of values from type=a|b|c
        $bedrooms = explode('|', $_GET['bedrooms']);
        
        
        // set compare for the meta_query
        // - http://codex.wordpress.org/Class_Reference/WP_Query
        $meta_query['relation'] = 'OR';
        
        
        foreach( $bedrooms as $bedroom )
        {
    	    $meta_query[] = array(
                'key'       => 'bedrooms',
                'value'     => '"' . $bedroom . '"',
                'compare'   => 'LIKE',
            );
        }
    	
    	
        $query->set('meta_query', $meta_query); // update the meta query args
        
        return; // always return
    }
    

    This is the code I have on the page I want to have filtering:

    <div id="search-houses">
    <?php 
     
    	$field = get_field_object('bedrooms');
    	$values = explode(',', $_GET['bedrooms']);
     
    	?>
    	<ul>
    		<?php foreach( $field['choices'] as $choice_value => $choice_label ): ?>
    			<li>
    				<input type="checkbox" value="<?php echo $choice_value; ?>" <?php if( in_array($choice_value, $values) ): ?>checked="checked"<?php endif; ?> /> <?php echo $choice_label; ?></li>
    			</li>
    		<?php endforeach; ?>
    	</ul>
    </div>
    <script type="text/javascript">
    (function($) {
     
    	$('#search-houses').on('change', 'input[type="checkbox"]', function(){
     
    		// vars
    		var $ul = $(this).closest('ul'),
    			vals = [];
     
    		$ul.find('input:checked').each(function(){
     
    			vals.push( $(this).val() );
     
    		});
     
    		vals = vals.join(",");
     
    		window.location.replace('<?php echo home_url('find-my-apartment'); ?>?bedrooms=' + vals);
     
    		console.log( vals );
     
    	});
     
    })(jQuery);	
    </script>
    

    This is the page: http://tlc.mainteractivegroup.com/find-my-apartment/

    The first problem is that it is giving me a PHP error on this line:<?php foreach( $field['choices'] as $choice_value =>

    The second problem is, when I add ?bedrooms=3 or any other number to the URL it goes to a 404 page.

    The third thing I noticed – don’t know if this matters or not but when I add ?post_type=apartment to the URL it brings up the page just fine.

    So I really need some help getting this part at least functional. I also don’t really understand completely how this function interacts with the existing loop I have on the page. You can see below the PHP error I have a loop that displays out all the apartments with the custom fields. Do I need to do anything to change that loop for this to work?

    Thanks in advance!

  • Hi Elliott,

    Thanks for your suggestion, I did try that, and the value was appearing. But I actually got it working!

    The problem was the double quotes in the shortcode.

    [fancygallery id="1" album="6"]

    If I removed the double quotes, it worked.

    [fancygallery id=1 album=6]

    But I could not tell the client to always delete the double quotes when inserting a shortcode, so I kept the short code as-is:

    [fancygallery id="1" album="6"]

    and within advanced custom fields, I changed the format setting for the Text field type to “Convert HTML into tags” instead of “No formatting”

    It works now!

    Thanks,

    JC

Viewing 25 results - 18,751 through 18,775 (of 21,363 total)