Support

Account

Forum Replies Created

  • And I think this simpler example would also work (replace the name of the custom field for featured in both examples):

    $args = array (
    	'post_type' => 'nieuws',
    	'posts_per_page' => 1,
    	'orderby' => 'date',
    	'order' => 'DESC',
    	
    	'meta_key' => 'custom_field_featured',
    	'meta_value' => 1,
    	'meta_compare' => '='
    );

    Veel succes 😉

  • Ok, so you want to only display the latest featured post, right?

    You need to specify everything in the WP_Query – there’s no need for additional checking, if you only want one post. Use the meta_query, like this:

    $args = array (
    	'post_type' => 'nieuws',
    	'posts_per_page' => 1,
    	'orderby' => 'date',
    	'order' => 'DESC',
    	'meta_query' => array(
    	     array(
    	        'key'		=> 'published',
    	        'compare'	=> '=',
    	        'value'		=> 1
    	    )
        ),
    );

    You can find more examples of such queries here: http://www.advancedcustomfields.com/resources/how-to/how-to-query-posts-filtered-by-custom-field-values/

  • Well, either set the field “web_address” to “required” or check for existence of the field first before creating the paragraph with the link.

    <?php if (get_field('web_address')) { ?>
      // your code
    <?php } ?>

    And I don’t think the link is to the page URL when not filled out in the backend, it’s probably just empty. Try this:

    echo get_field('web_address')

    And you should get nothing for an empty field.

  • Hi,

    in your example you’re checking the whole array of “featured”. Well, you’re already in the loop, so you’re already just working with a single post – and that post can either have the “featured” field on or off.

    If you have the ‘featured’ field as a boolean (true/false), you can just edit your IF line to this:

    <?php if(get_field('featured')) { ?>

    And if you’re setting this field to something custom, just check it against that value:

    <?php if(get_field('featured') == 'custom_value') { ?>

    … ad as far as getting only one post (last) – fix your query, you can set “posts_per_page” to -1 to include all of the featured posts.

  • Yes.

    You can include the (free) Advanced Custom Fields plugin within a free or premium theme/plugin.

    You can include your (premium) purchased Add-ons within a premium theme/plugin as long as it is made clear in the copyright / information that the Add-ons are not to be used or distributed outside of the premium theme/plugin.

    You must remove the update script from each Add-on to prevent distribution of updates. Instructions are included in the Add-on readme.txt file

    You can not include (premium) purchased Add-ons within a free theme/plugin.

    More info here.

  • Well, create a page with a url like this

    site.com/articles/article_with_gallery/page1

    You assign the ACF gallery to “article_with_gallery” and you grab the last part of the URL (“page1”), substring the “page” away and you get the current position for the gallery (=show first image on this page).

    Then you just display the first image from the gallery (it’s a simple array). For the next page, the next gallery image.

    The navigation (previous/next gallery image) simply takes you to the next/previous page in the URL.

  • Well, you probably changed the default display of the date in ACF field settings. The php function strtotime cannot work with french dates.

    Go to ACF field settings for date_picker and set it to YYYYMMDD

  • You’re not using the correct piece of code. If you want to use date_i18n, you have to set the language of your WordPress to English. This is a WP specific function.

    To use the setlocale method, use this code inside the loop (the setlocale on top is OK):

    // FIRST, SET THE WAY YOU WANT TO FORMAT DATE
    // DETAILS HERE - https://php.net/strftime
    $dateformatstring = "%A le %d %B, %Y";
    
    // THEN, CONVERT THE FIELD FROM ACF TO UNIX TIMESTAMP
    $unixtimestamp = strtotime(get_field('data_picker'));
    
    // NOW ECHO THE ENGLISH DATE USING PHP'S strftime
    echo strftime($dateformatstring, $unixtimestamp);
  • Ha 🙂 I thought you were trying to get it in french the whole time…

    No big deal, just change the “setlocale” line of code to this:

    setlocale(LC_ALL, array('en_GB.UTF8','en_GB','english'));

    This sets up everything for UK english. If you want USA english:

    setlocale(LC_ALL, array('en_US.UTF8','en_US','english'));

    You can specify the values either in an array (like i did here) or as a sequence of string (as shown above with the french example).

  • And what is the current output of your code? What do you see in the browser?

  • Try this with the first (PHP) solution (replace the setlocale line):

    setlocale (LC_ALL, 'fr-FR.utf8','fra');

    There’s a bunch of locale codes … the top one works, but here’s a big discussion on this topic: Zut alors! Mon dieu! 🙂

  • You could setup your repeater field with a date and text field (see attached image). Then under the selected page / post type, just fill the repeater rows with dates (using date picker) and corresponding dates.

    Then on the page (I’m using a custom post type “Movies” in this example – and a template “single-movie.php”) just put this PHP code to get “quote of the day”:

    <?php
    
    // GET TODAY'S DATE IN THE SAME FORMAT AS YOUR DATE SUB-FIELD
    $today = date('Ymd'); // 20140503
    
    // CHECK IF REPEATER HAS ROWS
    if( have_rows('quote_of_the_day') ):
    	
     	// LOOP TROUGH REPEATER ROWS
        while ( have_rows('quote_of_the_day') ) : the_row();
            
            // IF THE REPEATER SUB-FIELD MATCHES TODAY'S DATE, SHOW QUOTE SUB FIELD
            if (get_sub_field('date') == $today) {
            	 the_sub_field('quote');
            }
            
        endwhile;
        
    endif;
    
    ?>
  • And if you have your blog set to french, you can just do these steps in the loop:

    // FIRST, SET THE WAY YOU WANT TO FORMAT DATE
    // DETAILS HERE - http://php.net/manual/en/function.date.php
    $dateformatstring = "l d F, Y";
    
    // THEN, CONVERT THE FIELD FROM ACF TO UNIX TIMESTAMP
    $unixtimestamp = strtotime(get_field('data_picker'));
    
    // NOW ECHO THE FRENCH DATE USING A WORDPRESS FUNCTION
    echo date_i18n($dateformatstring, $unixtimestamp);
  • Ok, so let’s say ‘data_picker’ is your date field name in ACF. Set the locale before you go into the loop:

    <?php setlocale(LC_ALL, 'fr_FR'); ?>

    Then inside the loop do these steps:

    // FIRST, SET THE WAY YOU WANT TO FORMAT DATE
    // DETAILS HERE - https://php.net/strftime
    $dateformatstring = "%A le %d %B, %Y";
    
    // THEN, CONVERT THE FIELD FROM ACF TO UNIX TIMESTAMP
    $unixtimestamp = strtotime(get_field('data_picker'));
    
    // NOW ECHO THE FRENCH DATE USING PHP'S strftime
    echo strftime($dateformatstring, $unixtimestamp);
  • Hi,

    you can just create a dropdown field with the hour values and then use PHP to format it properly for display or calculations.

    If you want minute-specific time, use a number field.

  • Hi,

    I’m not sure what you’re asking/doing, but I think you should use the proper WordPress way to set this up.

    Create a custom post type (Movies), then create a custom taxonomy (Genres), connect the taxonomy to the custom post type. You can use the CPT UI plugin for this, this Movies&Genres is literally the suggested example when you create your first CPT & Taxonomy.

    Once you have this connected, you will automatically get “checkboxes” under your Movies posts and you can set your genres per movie.

    When you want to loop trough a Genre, just use a WP_Query that filters by custom taxonomy. Here’s an example of that code:

    $args = array(
        'post_type' => 'movies',
        'tax_query' => array(
            array(
                'taxonomy' => 'genres',
                'field' => 'slug', //can be set to ID
                'terms' => 'action' //if field is ID you can reference by cat/term number
            )
        )
    );
    $query = new WP_Query( $args );
  • Hi,

    it’s simple, just create the variable first (to keep it clean) and then use it instead of the field name, like this:

    $username = 'John'; // get this yourself
    $dynamic_field_name = 'adwords_cost_for_' . $username;
    
    echo the_field($dynamic_field_name, 'option');
  • There is nothing to activate – just start using it, it will work. The activation codes are a remainder from V3 if I remember correctly. It’s working fine without activation anyway.

    ACF v5 will have an activation code though.

  • If you want to only display posts from a certain category id (or array of category ids), it’s just one extra line in the WP_Query arguments, like this:

    $query = new WP_Query( 'cat=2,6,17,38' );

    If you don’t want to use ID’s, you can do this:

    $query = new WP_Query('category_name=staff');

    You can of course combine this with the sorting by date from above – this is just one of the arguments.

  • You could use WP_Query for your basic loop (sorted by custom field ‘start_date’) like this:

    $args = array(
    	'post_type'		=> 'your_custom_post_type',
    	'posts_per_page'	=> -1,
    	'meta_key'		=> 'start_date',
    	'orderby'		=> 'meta_value_num',
    	'order'			=> 'DESC'
    );
     
    $wp_query = new WP_Query( $args );
    
    while( $wp_query->have_posts() )
    {
    	$wp_query->the_post();
    	// now use get_field() for custom fields
    }
  • Hi,

    This is how you should use date_i18n with ACF:

    $dateformatstring = "l d F, Y";
    $unixtimestamp = strtotime(get_field('date_picker'));
    echo date_i18n($dateformatstring, $unixtimestamp);

    This depends on your blogs language setting. If you want to manually specify the locale in PHP, ignoring WordPress, you can do it like this:

    setlocale(LC_ALL, 'fr_FR');
    echo strftime("%A le %d %B, %Y");
    //with day of the week = mercredi le 18 septembre, 2013
  • You need to be more specific. If the sliders are always a different size, you could add another ACF field for width and height and then use that field to set width and height in the template file.

    For example:

    <div class="flexcontainer">
        <div id="first-slider" class="flexslider" style:"width:<?php echo get_field("slider_width") ?>">
            <ul class="slides">
            ...
            </ul>
        </div> 
    </div>

    If you have control over the javascript settings, just include the flexslider configuration inside the page (in a script tag) and again use ACF field for dimensions

    There is also a strict javascript approach (when you don’t know the dimensions of images inside the slider).

    var evenSliderHeight = function(slideContainer, slideItem) {
      var slider_height = 0;
      var $slider_slide = $(slideContainer).find(slideItem);
      $slider_slide.each(function() {
        var __height = $(this).outerHeight(true);
        if ( slider_height < __height ) {
           slider_height = __height;
        }
      });
      $slider_slide.css('min-height', slider_height);
    };
    evenSliderHeight('.flexslider-container', '.slide');
  • You don’t need “the_row()” on the first line. The correct code would be:

    <?php if(have_rows('activity_links')): ?>
      <h3>Links</h3>
      <ul>
        <?php while(have_rows('activity_links')): the_row(); ?>
        <li><a href="<?php echo the_sub_field('link_url'); ?>"><?php echo the_sub_field('name_for_link'); ?></a></li>
        <?php endwhile; ?>
      </ul>
    <?php endif; ?>
  • Aha, sure, just use the WordPress function for formatting dates in different languages.

    $dateformatstring = "l d F, Y";
    $unixtimestamp = strtotime(get_field('date_picker'));
    echo date_i18n($dateformatstring, $unixtimestamp);

    This is dependent on your blog language setting. More info here: http://codex.wordpress.org/Function_Reference/date_i18n

    If you can’t set blog language to french, you can also do it with PHP only.

    setlocale(LC_ALL, 'fr_FR');
    echo strftime("%A %e %B %Y");

    Another example with day of week and month (french):

    setlocale(LC_ALL, 'fr_FR');
    echo strftime("%A le %d %B, %Y");
    //with day of the week = mercredi le 18 septembre, 2013
  • Now it’s just a matter of php-array trickery to generate this query from array.

    // GET RECIPES THAT HAVE A RELATIONSHIP TO PRODUCTS ON THE CURRENT PAGE - dynamically
    $recipes_dynamic_meta_query = array(
    	'post_type' => 'recipes',
    	'meta_query' => array(
    		'relation' => 'OR'
    	)
    );
    
    foreach($product_ids as $product_id) {
    	array_push($recipes_dynamic_meta_query['meta_query'], array(
    		'key' => 'products_under_recipes',
    		'value' => '"' . $product_id . '"',
    		'compare' => 'LIKE'
    	));
    }
    

    Run this string trough get_posts and you’re set!

    $recipes_manual = get_posts($recipes_dynamic_meta_query);

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