Support

Account

Forum Replies Created

  • You’ve got to be a bit more specific if you want help.

  • Not sure why my original answer got marked as private but here’s what I originally provided as solution:

    <?php if( get_field('preco') && get_field('checked')): ?>
    <div class="container"> 
    	<div class="row">
    		<div class="col">
    			<?php if( get_field('preco') ): ?>
    			<p> <?php the_field('preco'); ?> </p>
    			<?php endif; ?>
    		</div>
    	
    		<div class="col">
    			<?php $ratingstar = get_field('checked'); ?>
    			<span class="fa fa-star <?php if ($ratingstar >= 1) { echo 'checked';}?>"></span>
    			<span class="fa fa-star <?php if ($ratingstar >= 2) { echo 'checked';}?>"></span>
    			<span class="fa fa-star <?php if ($ratingstar >= 3) { echo 'checked';}?>"></span>
    			<span class="fa fa-star <?php if ($ratingstar >= 4) { echo 'checked';}?>"></span>
    			<span class="fa fa-star <?php if ($ratingstar == 5) { echo 'checked';}?>"></span>
    		</div>
    	</div>
    </div>
    <?php endif; ?>

    The “if” condition in the first line (together with “endif” in the last line) hide the content if there is no value.

  • We need a little more info. The first place you should probably look is the template where the field content is output. Is it on a regular page or in a post or on an archive page? Can you post the template code here?

  • I’m not quite understanding the problem here. First you say:

    If I call the field in the custom section I get a result (15), so I know the field has a value.

    And then you say:

    I can give the shortcode a parameter for ID, but in that custom section, I can’t get the actual ID to put it in the shortcode.

    Also, what do you get if you do var_dump($id_i_need)?

  • Have you added the field afterwards? Have you re-saved the posts then? Are the other fields coming from a different field group or are they in the same group?

  • Is the custom field name correct? Perhaps you have a typo there?

  • It’s hard for me to imagine what your setup looks like.

    So, you have a custom post type with taxonomy (categories) and you want to show different fields depending on which category is selected? What exactly does “doesn’t work for the other” mean? Are the same fields shown as for the first restaurant? Is nothing coming up at all? I guess a couple of screenshots would help, or a clear explanation of each field group setting.

  • You can change field labels but not field names (slugs) without losing the connection to previously entered data.

    For example, if you have a text field with label “Camera Lens 1” and field name “camera_lens_1” you can change the label and the new label text will be shown in the templates where this label is used. But if you change the field name it will not update the old data in the database, so you would start with an empty list again. The old data isn’t lost, it’s still in the database, but it won’t be accessible unless you change the name back to the old one.

    I hope I’ve understood your question correctly. For more specific answers you’ll have to post your field setup exactly.

  • Huh, strange, I just tested it again and now it works. Could this have been a network issue? Is there any AJAX action performed when selecting a link? But then again, why would it work in one browser and not in another? Very strange. 🤔

  • What does $recent["news_source"] return? I don’t think it returns anything useful because there is no “news_source” item in the post array. Try it with get_field('news_source') or possibly get_field('news_source',$recent['ID']).

  • I just noticed that I have the same problem. But only in Safari. 🙁

    ACF version is 5.10, and WordPress 5.8, by the way.

  • I would think the data is sanitized to specifically prevent JS from being entered because this is a major security issue (script injection). The error message suggests that this is an error on the WordPress level, not with ACF itself.

  • Well, if the output is set to array you can’t just do if($colours == 'blue'), you need to either loop through the array and print the results accordingly or you need to access the array items directly. How to do this is explained in the documentation. But apparently you don’t even need the array output, you could just output the value since you’re not doing anything with the labels.

    I guess for you the example under “Conditional logic” in the documentation would be appropriate:

    <td>
    <?php if($colours && in_array('yellow',$colours) { ?>
    YES
    <?php } ?>
    </td>
    <td>
    <?php if($colours && in_array('red',$colours) { ?>
    YES
    <?php } ?>
    </td>
    
    <td>
    <?php if($colours && in_array('blue',$colours) { ?>
    YES
    <?php } ?>
    </td>
    <td>
    <?php if($colours && in_array('green',$colours) { ?>
    YES
    <?php } ?>
    </td>

    (not tested)

  • OK, a couple of observations:

    Why are the queries run inside a default while ( have_posts() ) : the_post(); loop? Remove that loop or move the additional queries outside of it and go from there.

    To debug this I would do a standard query first and var_dump or print_r the return value of the custom field in question to see what values are actually returned. Is it actually a string, as you seem to be testing for? Or is it true/false or 1 or 0 as integers?

    You should use wp_reset_postdata(), not wp_reset_query(), as this is only for use with query_posts(), as far as I understand, which isn’t recommended anyway (source: https://developer.wordpress.org/reference/functions/wp_reset_query/).

    You can probably use a basic query, as described on https://www.advancedcustomfields.com/resources/query-posts-custom-fields/, since you are just querying for one field anyway.

  • Thanks, that clarifies things. Would be nice to have more consistency in the examples and some explanation like that in the documentation.

  • I assume you are using the default Gutenberg mode? That can’t be disabled, as it’s the core of the new post editing experience. What you can do is install the Classic editor to return to the classic post editing mode. Then you can hide the default content field and only use the custom fields you have.

  • This reply has been marked as private.
  • You have to show us your changed code if you want help, we aren’t psychic. But anyway, here is the modified code from your first example, assuming your field is now a taxonomy field with return value “Term Object”:

    
    <div class="audio-tags">
    <?php
    	$tags = get_field("etiquetas");
    	foreach($tags as $tag){
    ?>
    	<a href="<?php echo(esc_url(get_term_link($tag))); ?>"><?php echo($tag->name); ?></a>
    <?php
    	}
    ?>
    </div>
    

    And the adjusted CSS for this would be:

    
    .audio-tags {overflow: hidden;}
    .audio-tags a {
    	position: relative;
    	display: inline-block;
    	margin-right: .5em;
    }
    .audio-tags a:before {
    	content: '';
    	width: .25em;
    	height: .25em;
    	position: absolute;
    	background-color: blue;
    	border-radius: 100%;
    	left: -.5em;
    	top: 50%;
    	transform: translateY(-50%);
    }
    
  • Oh, I see. Well, technically it’s not possible to determine when a line break occurs because that depends on the viewport width, and that’s variable, depending on the user’s preference or the display size. But you can work around this with some CSS trickery:

    Assuming the tags are output as list like this:

    
    <ul>
    	<li>Upbeats</li>
    	<li>Keyboards</li>
    	<li>Positive</li>
    	<li>Useful</li>
    </ul>
    

    You can use this CSS to make it look as you want:

    
    ul {
    	margin: 0;
    	padding: 0;
    	list-style: none;
    	overflow: hidden;
    }
    li {
    	position: relative;
    	display: inline-block;
    	margin-right: .5em;
    }
    li:before {
    	content: '';
    	width: .25em;
    	height: .25em;
    	position: absolute;
    	background-color: blue;
    	border-radius: 100%;
    	left: -.5em;
    	top: 50%;
    	transform: translateY(-50%);
    }
    

    Basically what this does is add the bullet points to the list items as generated content (:before pseudo-element). By positioning them absolutely, they are taken out of the natural flow of content, so they are out of the boundaries of the list container at the start of each line. And the overflow: hidden on the list container makes them disappear, for that matter.

  • oEmbed is a function that is only meant to embed media from third-party websites, i. e. it won’t work with local media files. There is a tutorial on how to embed own videos with ACF at https://speckyboy.com/html5-video-wordpress-custom-fields/

  • Usually formatting is applied and it works like a regular content field; there must be something else messing with the output. What’s your code?

  • I’d say, in each iteration of the foreach loop, do a str_replace where you replace the comma with an empty string before you echo it:

    
    $tag = str_replace(',','',$tag);
    

    And as a side note: even though I don’t know the rest of your HTML, I doubt that h6 is the semantically correct element to use. It would probably be better to use a div instead; to make it look as you like you should style it with CSS.

  • The forum layout error has been fixed; supposedly it was some unclosed code tag or something like that.

    Anyway, this is what I mean:

    
    <?php while ( have_rows('belasting_laag', $product_id) ) : the_row(); ?>
    <?php if (get_sub_field('prijs',$product_id)): ?>
    					<li>
    <?php the_sub_field('prijs',$product_id); ?>
    					</li>
    				<?php endif; ?>
    			<?php endwhile; ?>
    

    Does that change anything?

  • Oh I just realize now that we’re talking about the Code module of Divi here. Yeah, no, as far as I know it’s not possible to execute PHP in there, it’s only meant for static HTML. But what you can probably do is load the ACF value with a shortcode, too.

  • Classic editor should have nothing to do with it, ACF works with Gutenberg, too. And the JS errors have nothing to do with this as well.

    It’s hard to tell why it isn’t working (without classic editor) from the little snippet you provided. It would help if you showed us all of the template code and perhaps a screenshot of the field setup in the admin screen.

Viewing 25 posts - 1 through 25 (of 104 total)