Support

Account

Forum Replies Created

  • I’m not sure what you’re trying to do but yeah, you can’t have HTML as input values. You need to use simple strings and then do a conditional query for the value string in your template, and output appropriate code.

  • As far as I understand it, according to https://developer.wordpress.org/reference/classes/wp_query/#taxonomy-parameters the terms must be an array of terms, not a category object, as your $category is returning. So, you need to loop over the $category object to retrieve the single terms and store them in an array first.

  • You need to echo the field value, not just return it. get_sub_field() is for returning it (i. e. to store it in a variable and do something with it afterwards), and for directly echoing it you would use the_sub_field() (spot the little difference between “get” and “the”).

    However, you can, of course, also go the little detour of storing the value in a variable and then echoing that variable; so, in your example, you would do:

    
    $sub_value = get_sub_field(‘document_text’);
    …
    …
    echo($sub_value);
    
  • Shouldn’t it rather be

    
      $ad_args = array(
        'post_type'       => '3d_drucker',
        'orderby'         => 'rand',
        'meta_query'      => array(
          array(
            'key'     => 'printer_type',
            'value'   => 'SLS',
          )
        )
      );
    

    (i. e. different key)
    Check the field name/slug that you want to query.

  • The documentation for acf_form_head() says:

    This function must be placed before any HTML has been output, preferably above the get_header() function of your theme file.

    Sounds like you cannot append that to wp_head, you need to place it in your template, right before get_header(), or you need to use a different action hook, perhaps get_header?

  • Yeah, you mixed something up in your template (get_header() twice, a missing closing bracket etc.). Change it to this right here:

    
    <?php
    	/*
    		Template Name: Page with custom fields
    		Template Post Type: ACF
    	*/
    
    get_header();
    ?>
    
    	<div id="primary" class="content-area">
    		<main id="main" class="site-main" role="main">
    
    			<?php while ( have_posts() ) : the_post(); ?>
    
    				<?php get_template_part( 'template-parts/content', 'page' ); ?>
    
    				<?php
    					// If comments are open or we have at least one comment, load up the comment template
    					if ( comments_open() || get_comments_number() ) :
    						comments_template();
    					endif;
    				?>
    
    			<?php
    				endwhile; // end of the loop.
    				if (get_field('proprietario')) {
    			?>
    			<strong>PROPRIETARIO:</strong> <?php the_field('proprietario'); ?><br />
    			<?php
    				}
    				if (get_field('indirizzo')) {
    			?>
    			<strong>INDIRIZZO:</strong> <?php the_field('indirizzo'); ?><br />
    			<?php
    				}
    			?>
    		</main><!-- #main -->
    	</div><!-- #primary -->
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>
    

    The file should be in your theme folder. See if you can select the template now. Here is an explanation on how to create a page template, just for your information (or to compare whether you’ve done everything correctly): https://developer.wordpress.org/themes/template-files-section/page-template-files/#creating-custom-page-templates-for-global-use

  • Sounds like you need to query the posts by custom field, as explained at https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters (and do a separate query for posts NOT containing the custom field value, or whatever).

  • First of all, don’t hijack other people’s threads. Your question might seem similar to another person’s issue but it’s likely a whole different problem and approach to the solution. Always create a new, separate thread for your question.

    Secondly, a vague description of your problem isn’t any useful; you need to provide more than that – a description of what you have tried so far is a start, but your actual code would be best. That way we can see what’s wrong and don’t have to play an endless guessing game.

  • I don’t quite get it. So, get_field('weather') is a checkbox field type, right? But what do you mean with “default checked radio button”? It looks like you are creating radio buttons on the fly from the checked checkboxes, i. e. if three checkboxes are checked, three radio buttons will be created.

    What’s the point of all this?

  • “It doesn’t work” could mean anything. It’s clear that something doesn’t work because otherwise you wouldn’t be posting here. But please be more specific as to what exactly isn’t working. What is the output of the code? Is it not printing the values at all? Or perhaps it’s not even the PHP but an error in the CSS? Look at the output source code and see if it prints anything for the_sub_field('column_start'); etc. If that’s all working then the error is in the CSS itself.

    I’m going to look over the fact that CSS should at least go into the header of the HTML document, not in the body, but definitely you need to address each image in the repeater individually (as in your second example) because otherwise the last value that is printed will style all images. But you can actually get the current row index inside a has_rows() loop with get_row_index(); no need for the incementing counter variable.

    Now, I’m not too experienced with CSS grid yet, as I’ve mostly avoided it for reasons of browser support, but I’m skeptical about the row and column placement properties in combination with auto-fill columns and a fixed number of rows. If the user specifies to place the image in column 100 and row 10, how is that going to work with the specification of the grid template rows and columns? I think therein lies the actual problem; it’s not an ACF repeater issue.

  • You could transfer all files with FTP from staging to production, export the database from staging, import it on production, and then use Search Replace DB (as mentioned above) to search for the staging domain and replace it with the production domain, and everything should be running like before. That’s how I’m doing it when moving sites.

  • Sounds like you would have to register multiple taxonomies and link the fields to these.

  • I suppose where you have <img class="img-fluid" src="img/project-01.jpg"> you would add the template code for the image field, as explained in the documentation. The important thing to watch out for is the return format in the field settings; the simplest is probably “Image ID” and then use the template code from the first example under Template Usage.

  • Here is a quick and basic tutorial:

    Assuming your pages are using the default page template (page.php in your theme directory on the server) and you only want the field values on certain specific pages, not everywhere:

    1. Make a copy of page.php and name it whatever you like (e. g. page-acf.php)
    2. Open the PHP file in a code editor or a plain text editor of your choice
    3. At the very top of the file, add this code to let the system know that this is a global template:
      
      <?php
      	/*
      		Template Name: Page with custom fields
      		Template Post Type: page
      	*/
      	get_header();
      …
      …
      

      (you can use whatever text you like for the template name)

    4. Add the template code for which John Huebner gave an example after the the_content() function, like so:
      
      the_content();
      if (get_field('proprietario')) {
      ?>
      <strong>PROPRIETARIO:</strong> <?php the_field('proprietario'); ?><br />
      <?php
      }
      if (get_field('indirizzo')) {
      ?>
      <strong>INDIRIZZO:</strong> <?php the_field('indirizzo'); ?><br />
      <?php
      }
      …
      …
      …
      

      and so on and so forth.

    5. In the admin area, go to the ACF field groups and edit the group that contains these fields. Change the location rules to “page template equals Page with custom fields” (or whatever you named your page template)
    6. And lastly, edit the pages where you want the fields to show up and in the sidebar under “Document”, open the “Page attributes” panel and select the template.

    That sounds like a lot but it’s just a one-time setup and then the only thing you need to do is select the appropriate page template whenever you want to show the fields.

  • I’ve been pondering the same about the use of Gutenberg for websites with bespoke layouts (i. e. where editors aren’t supposed to place whatever blocks they like in whichever order they like). My take is this: whether to use blocks or metaboxes depends on where you want the content to appear eventually. If you need reusable custom content within the main content where the editors can decide themselves how many blocks they want to insert, you’d use blocks; if you need custom content in areas outside of the main content and/or want to restrict the liberty of editors you’d use metaboxes.

  • I haven’t done this and don’t think that’s easily possible but alternatively you could have two separate fields, one for images and one for other files, and have a conditional field (select/radio button) to show the right field depending on the editor’s choice.

  • Is there any particular reason why you are using shortcodes and not PHP code in the template(s)? Because that would be the easiest thing with template code instead of shortcodes.

  • With “frontend” you mean the public facing website? Or the admin area? Because all the text field does in the templates is output the text, so, if you need a class you need to wrap the output with an element:

    
    <div class="example"><?php the_sub_field('episode_explanation'); ?></div>
    

    And if you need a unique identifier you can use get_row_index() and add it as ID or class:

    
    <div class="example" id="ex<?= get_row_index() ?>"><?php the_sub_field('episode_explanation'); ?></div>
    
  • I just had an idea and this thread has a point (someone there also mentions hotlink protection option in Bluehost Cpanel). It’s possible that the URLs are still pointing to the old site. What I’ve used in the past was Search Replace DB when I moved a WordPress installation to a new domain. You search for a string (e. g. old domain name) and replace it with a new one.

    And yes, you can, of course, check the database with phpMyAdmin. The media paths are in the wp_posts table where post_type = attachment

  • There are differences between a field label and a placeholder. A placeholder as in HTML’s placeholder attribute must not replace a <label> element, because this is necessary for accessibility. The placeholder attribute should only contain explanatory text that helps convey the intended content of the field. What you can do is use CSS (and possibly JavaScript) to make the label look like a placeholder (as demonstrated on https://material.io/components/text-fields). Alternatively (although not recommended), you can hide the label by positioning it outside the viewport using CSS and add the label text to the placeholder attribute with the 'form_attributes' => array() parameter as described in the documentation.

  • Hmm, I guess there are two solutions to this. The first would be to create a nested repeater, i. e. one repeater for the event dates, and inside that, another repeater for event title and description. And then you loop over the dates, and in each iteration, you loop over the nested repeater to retrieve the other two field values. The documentation describes such a scenario in the section titled “Nested loops”.

    The other option would be to create an associative array, but for that, you can’t use array_push(), you need to use the square bracket notation with the date string as key, like so:
    $events[$event_day] = $single_event;

  • In your foreach loop you would simply retrieve the value of the URL field inside the repeater and add an anchor element, as the documentation describes in the section titled “foreach loop”, like so:

    
    foreach ($hero_banner_background_images as $i) {
    	$image = $i['hero_banner_background_image'];
    	$url = $i['hero_banner_url'];
    	…
    

    Forget the $hero_banner_url = get_field('hero_banner_url'); you have there previously, outside the loop.

  • From the fact that the media library is empty, it sounds like this has nothing to do with ACF per se but with WordPress itself, like, the clone script has made a copy of the site but not a real clone. Doing an internet search for “wordpress emtpy media library” brings up many suggestions for possible reasons and solutions, wrong directory permissions for the uploads directory being among them. Another suggestion was to change the file upload path in “Settings → Media” and then change it back to default blank. Also, perhaps re-updating WordPress (in “Dashboard → Updates”) might help?

  • I suppose you should set two conditions: “if post type = page” and “if post category = …” (or alternatively “if post taxonomy = …”). Pages are just posts of a different type than standard posts.

  • Could you show us more context, please? It seems like that’s something outside of the code you provided. What code comes before that?

    Edit: Oh, wait, I just saw this:
    You are doing <?php echo in the very beginning. Remove that echo statement and see if that helps.

Viewing 25 posts - 51 through 75 (of 104 total)