Support

Account

Forum Replies Created

  • I see. I decided to go with normal text field for the ingredients and add the ingredients as tags then. Thank you so much for your help πŸ™‚

  • Thank you John!

    This does indeed save the taxonomy terms to each field!

    However, I also found out that this does not make the recipe post-type “acknowledge” these terms tagged to the post, which is a function I wish to have as well. This is so that the recipe ingredients are terms which users can click to view more recipes with this particular ingredient.

    Does that make sense? For example, if I have the ingredient “chicken” in my repeater taxonomy field, it will be automatically tagged in the recipe post-type as a “chicken” term.

  • Hi… update. I got so frustrated and decided to use Suicide plugin to empty all WordPress posts, leaving only the settings and functions intact.

    Then I created new ACF fields (one for thumbnail and one for gallery) for Pages and tried uploading media to both fields. Works beautifully.

    Now I’ll continue populating the rest of my site hoping this non-saving of ACF won’t occur again, still don’t know what was wrong.

  • Hi @Intrepidrealist, thanks for your reply!

    I know but I’m unable to start a new forum topic. I did try turning off all plugins, which did not change anything. Have been googling extensively and tried everything but nope… still doesn’t save new data on existing / new fields.

    Adding a new field works fine, I do see the new field , but updating any existing or new field actually saves the uploaded image (I found them in WordPress > Media) but somehow the image doesn’t get “attached” to the post in the ACF.

  • Hi, I am having the same problem πŸ™ I disabled ALL plugins and it still doesn’t work. I’ve no idea at what point this stopped working, I basically have a ACF and ACF: Gallery. I added some gallery images to a post (page actually) successfully, and now when I tried to add a new ACF image field it never saved. So I tried to go back and add images to the gallery ACF of another page and when I hit “update” the field disappears although my images are uploaded when I check my Media. Help!

  • Hi @Jonathan,

    No it isn’t my theme, it’s just the placement of the “related posts” is on the sidebar which is out of the loop due to design issues πŸ™‚

    Hmmm, I manually typed in this URL (http://website.dev/?company=240) and it still gives me an error. Let me recap for you again, so perhaps you could point out to me what I’m doing wrong T_T

    In my archives.php, here is the code:

    
    <?php // if is a link to Read More from company single related post
    if(isset($_GET['company'])){ ?>
    <?php
    $company_id = $_GET['company'];
    // Show all related posts from the company singular page.
    $items = get_posts(array(
    'post_type' => 'post',
    'meta_query' => array(
    array(
    	'key' => 'company_relationship', // name of custom field
    	'value' => '"' . $company_id . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
    	'compare' => 'LIKE'
    )
    )
    ));
    
    ?>
    <?php if( $items ): ?>
    <?php endif; ?>
    
    <?php } else { ?>
    <?php while ( have_posts() ) : the_post(); // The Loop ?>
    <?php get_template_part( 'content','excerpt' ); ?>
    <?php endwhile; ?>
    <?php } ?>
    
    

    In my single-company.php, here is the code:

    
    <?php 
    
    /*
    *  Query posts for a relationship value.
    *  This method uses the meta_query LIKE to match the string "123" to the database value a:1:{i:0;s:3:"123";} (serialized array)
    */
    
    $posts = get_posts(array(
    'post_type' 	=> 'post',
    'orderby'		=> 'ID',
    'order'			=> 'DESC',
    'posts_per_page'=> 1,
    'meta_query'	=> array(
    array(
    	'key' 	=> 'company_relationship', // name of custom field
    	'value' => '"' . get_the_ID() . '"', // matches exactly "123", not just 123. This prevents a match for "1234"
    	'compare' => 'LIKE'
    )
    )
    ));
    
    if( $posts ) { ?>
    <div class="relatedposts">
    	<h5>Related Posts</h5>
    	<?php foreach( $posts as $post ): ?>
    	<?php setup_postdata($post); ?>
    			<?php get_template_part( 'content', 'excerpt' ); ?>
    	<?php endforeach; ?>
    
    	<?php 
    	$company_ID = $post->ID; //get the id of the current company
    	$archive = get_post_type_archive_link('post').'?company='.$company_ID;
    	echo $archive;
    	?>
    	<a href="<?php echo $archive; ?>">View all</a>
    </div><!-- div.relatedposts -->
    <?php wp_reset_postdata(); ?>
    <?php } ?>
    

    I thank you in advance.

  • Hi @Jonathan,

    Ah, when I echo out $archive, I get ?company=862. Yet the Company’s Post ID is 240.

    I believe this is the same out-of-the-loop issue you also helped me with awhile back here!

    However, even when I manually changed the link to 240, the URL is still:

    http://website.dev/en/companies/COMPANY_NAME/?company=240

    Which still gives me the error. Is this URL format correct?

  • Hi Jonathan,

    I believe the code you provided above is the code to be put in archives.php right? I can’t get it to work unless the “View all” link from the company-single.php works, which doesnt:

    
    <?php 
    $company_ID = $post->ID; //get the id of the current company
    $archive = get_post_type_archive_link('post').'?company='.$company_ID;
    ?>
    
  • Hi, could anyone help me with this?

    I basically need a way to dynamically generate an archive of all normal posts that have a “relationship” with the Company-post-type.

    Thank you in advance.

  • @Jonathan: YOU. ARE. AWESOME.

    Here’s the code I used outside the loop to generate the field output for anyone else who’s searching to solve the same problem.

    
    <?php 
    $post_id = get_the_ID(); // if ACF is outside loop, use this to get post ID
    $post_objects = get_field('banner_selection', $post_id); // use second parameter to get the fields from this post
    echo $post_id // Optional: use this to check if the ID is correct for this post
    ?>
    <?php if( $post_objects ):  // if banner selection was made, show those ?>
    
    <?php foreach( $post_objects as $post): ?>
    	<?php setup_postdata($post); ?>
    	<?php get_template_part( 'banner','side' ); ?>
    <?php endforeach; ?>
    <?php wp_reset_postdata(); ?>
    
    <?php endif; // end if banner selection was made ?>
    
    

    To output selection fields for Post Object fieldtype in ACF.

  • Hey @elliot,

    Thanks for the suggestion! But as I have various companies, can the second parameter be generated dynamically?

    Or would simply creating a second loop suffice, much more easily?

    I’d value your input.

    Thanks!

  • Hi @elliot,

    I tried inserting
    <?php global $post; echo $post->ID; ?>
    and it gives me 862. But the post-id of the company-post-type is 240 (am I correct to say the post ID is the number in this URL: ../adm/wp-admin/post.php?post=240&action=edit )

    If I am correct in the above 2 things, this means that ACF isnt loading the selected banners from the company’s post-id and instead some other post’s. I am a newbie at php, would be really grateful if you could let me know how I can modify my code in my banners.php (which is called in my single-company.php) which has the code that I pasted in my previous post.

    EDIT: I have tried including the banners.php template INSIDE my loop and it works! Is there a way to make it work outside the loop, if I do not wish to create a secondary loop?

    P/S. Thanks for helping me hone in on the root of the problem! xx

  • Hi Jonathan,

    Yes the code is in banners.php which I’ve included in both single.php and single-company.php, thus I don’t see how come it doesn’t work on single-company.php but only on single.php πŸ™

    If it please you here is the code in its entirety on banner.php:

    <?php if ( is_single() || is_singular() ) : // for singular items only ?>
    
    	<?php while ( have_posts() ) : the_post(); ?>
    
    		<?php $post_objects = get_field('banner_selection');?>
    		<?php if( $post_objects ):  // if banner selection was made, show those ?>
    			<?php foreach( $post_objects as $post): ?>
    				<?php setup_postdata($post); ?>
    				<?php get_template_part( 'banner','side' ); ?>
    			<?php endforeach; ?>
    			<?php wp_reset_postdata(); ?>
    
    		<?php else: // if there are no selected banners, show random 5 banners ?>
    			<?php query_posts( array ( 'post_type' => 'banner', 'meta_key' => 'banner_type', 'meta_value' => 'sidebar', 'posts_per_page' => 5, 'orderby' => 'rand' ) ); // The Query ?>
    				<?php while ( have_posts() ) : the_post(); // The Loop ?>
    					<?php get_template_part( 'banner','side' ); ?>
    				<?php endwhile; ?>
    			<?php wp_reset_query(); // End Query, RESET ?>
    		<?php endif; // end if banner selection was made ?>
    
    	<?php endwhile; ?>
    
    <?php else : // for homepage/archive items only ?>
    
    	<?php query_posts( array ( 'post_type' => 'banner', 'meta_key' => 'banner_type', 'meta_value' => 'sidebar', 'posts_per_page' => 5, 'orderby' => 'rand' ) ); // The Query ?>
    		<?php while ( have_posts() ) : the_post(); // The Loop ?>
    				<?php get_template_part( 'banner','side' ); ?>
    		<?php endwhile; ?>
    	<?php wp_reset_query(); // End Query, RESET ?>
    
    <?php endif; // is_single() ?>

    On your second point though, the code is outside the loop. This *could* be the case, however I still have no idea why it wouldnt work for single-company.php when it works for single.php.

    Many thanks in advance!

  • Hi Jonathan and Wells5609;

    I’m getting more and more lost! Lol. Basically the posts which has selected a certain Company custom post shows up beautifully as “related posts” in that Company’s single-company.php using this query on my single-company.php.

    However I’ll require a link to “View More” after showing only 3 posts as related posts which should point to an archive page of posts which has the Company selected.

    Like Jonathan said, “since there’s no default archive for posts queried by meta value”, I am stuck πŸ™ Unfortunately, his solution yielded an error saying that no posts exist at the URL: http://example.com/companies/?company=225

    Helppp D:

  • In case I messed something up, here’s the code I used on my single-company.php to generate the Read More link:

    <?php 
    $company_ID = $post->ID; //get the id of the current company
    $archive = get_post_type_archive_link('post').'?company='.$company_ID;
    ?>

    and here’s the code on my archive.php page:

    <?php get_header(); ?>
    <?php // if is a link to Read More from company single related post
    if(isset($_GET['company'])){ ?>
    	Show all related posts from the company's singular page.
    <?php } else { ?>
    	<?php while ( have_posts() ) : the_post(); // The Loop ?>
                <?php get_template_part( 'content','excerpt' ); ?>
    	<?php endwhile; ?>
    <?php } ?>
    <?php get_footer(); ?>
  • Hi Jonathan!

    Thanks so much for your fast reply!

    You’re right, that’s exactly what I was looking for – creating an archive for posts queried by meta value from the “relationship” ACF.

    Although I had no idea we could query an archive with a GET parameter (am more of self-taught “developer” myself), your solution makes sense.

    I made a conditional statement with your if(isset($_GET['company'])){, but it gives me an error.

    The URL I was directed to with your read more link was:

    http://example.com/companies/?company=225

    Which doesn’t seem quite right. Is that where the problem lies?

    Thank you in advance!

    P/S. Haha, glad you like the name πŸ™‚

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