Support

Account

Forum Replies Created

  • Hi,

    If you are doing a secondary on a page, you’d need to pass the pagination argument into your WP_Query.

    https://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters

    
    $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
    $query = new WP_Query( array( 'paged' => $paged ) );
    

    Cheers.

  • It’s fine. I do that all the time for addition off-site links.

    Cheers.

  • Oh, forgot one more thing.

    remember to go to the backend, Settings->Permalink and click save. so your custom rewrite rule will be saved.

    Cheers

  • Hi,

    In cases like you, unfortunately the nature of wp’s url, you gonna have to add the rewrite rule yourself.

    You can have a look at add_rewrite_rule.
    https://codex.wordpress.org/Rewrite_API/add_rewrite_rule

    So, your code will look something like:

    
    function custom_rewrite_basic() {
        add_rewrite_rule('^mangas/([^/]*)/([^/]*)/?', 'index.php?chapters=$matches[2]', 'top');
    }
    add_action('init', 'custom_rewrite_basic');
    

    Cheers

  • So, your field’s return type is set to object, that’s is why your condition is always false. Because an object will not equal to a string.

    If you wanna check the condition by the post title, you try something like:

    
    $post_object = get_field('obits-second_visitation_location');
    
    if (! $post_object || $post_object->post_title != 'Announcement Pending'):
        ......
    

    Cheers.

  • One thing you can do is try to debug on what the actual returned value is.

    Try to do dump out the value before your if statement, and see if it’s actually ‘Announcement Pending’.

    Something like:

    
    var_dump(get_field('obits-second_visitation_location'));
    
    if (....
    ...
    

    Cheers.

  • When you run your foreach loop, you can also define an index variable. And you can use that index variable to get the prev and next.

    Something like:

    
    <?php 
        $project_gallery_thumbnails_images = get_field( 'project_gallery_thumbnails' ); 
    
        // let store a total count for later use
        $project_gallery_thumbnails_count = count($project_gallery_thumbnails_images);
    ?>
    
    <?php if ( $project_gallery_thumbnails_images ) :  ?>
    
        <?php foreach ( $project_gallery_thumbnails_images as $index => $project_gallery_thumbnails_image ): ?>
    
            <a class="thumbnail-link" href="#image_<?php echo $project_gallery_thumbnails_image['id']; ?>">
                <img src="<?php echo $project_gallery_thumbnails_image['sizes']['thumbnail']; ?>" alt="<?php echo $project_gallery_thumbnails_image['alt']; ?>" />
            </a>
    
            <div id="image_<?php echo $project_gallery_thumbnails_image['id']; ?>" class="lb-overlay" >
                    
                    <?php if ($index != 0): // dont do it on the first one ?>
                        <a href="#image_<?php echo $project_gallery_thumbnails_images[$index - 1]['id']; ?>">Previous Gallery Image ID</a>
                    <?php endif; ?>
                    
                    <a class="thumbnail-link-close" href="#page">
                        <img class="lazyload" src="<?php echo $project_gallery_thumbnails_image['url']; ?>" alt="<?php echo $project_gallery_thumbnails_image['alt']; ?>" />
                    </a>    
                    
                    <?php if ($index != $project_gallery_thumbnails_count - 1): // dont do it on the last one ?>
                        <a href="#image_<?php echo $project_gallery_thumbnails_images[$index + 1]['id']; ?>">Next Gallery Image ID</a>   
                    <?php endif; ?>
                                                        
            </div> <!--lb-overlay-->
    
        <?php endforeach; ?>
        
    <?php endif; ?>
    
    

    Cheers.

  • Do you have caching plugin on your site or your hosting? If you have caching, then it’ll serve the static cache file directly without running through your php code. You might want to consider using js to do the randomization in that case.

    Something like:

    
    <?php
        $availableImages = [];
    
        while (have_rows('repeater_field_name')): the_row();
            $availableImages[] = wp_get_attachment_image_url(get_sub_field('sub_field_name', 'full'));
        endwhile;
    ?>
    
    <script>
        var availableImages = <?php echo json_encode($$availableImages); ?>;
    
        jQuery(function($) {
            var randomImage = availableImages[Math.floor(Math.random() * availableImages.length)];
            $('.hero').css('background-image', 'url(' + randomImage + ')');
        });
    </script>
    

    Cheers.

  • Whoa! somehow your reply managed to break the css of this page. nice, i approved 😉

    anyway, to answer the 3) question. Yeah, if you wanna make it dynamic based on the post’s title, you can use the php’s strtolower function on the post_title.

    For example:

    
    <?php
        // field name
        $field_name = strtolower(get_the_title());    
    
        // get repeater values as array
        $appetizers = get_field($field_name);
    
        // calculate how many items first
        $items_count = count($appetizers);
    ...
    ...
    ?>
    

    Cheers

  • Usually when it return false is because there’s no value set on the post.

    Can you double check that
    1) your Map Field’s name is indeed called ‘google_map’?
    2) the value is also saved properly?
    3) your current post is indeed the post your are retrieving the value from? (do a var_dump(get_the_ID()) and see if the current post id is the same post id where you put the acf field)
    4) make sure you are not mis-using get_field and get_sub_field (we all make this mistake form time to time 😉 )

    Cheers

  • Oh, i was under the assumption that you are using the acf frontend form. My bad.

    The hook ‘prepare_field’ only get called on the acf’s rendered form.

    But if you are rendering the form yourself, you can try ‘load_field’ hook instead.
    Like this: acf/load_field/key=field_59ae96d970a06

    https://www.advancedcustomfields.com/resources/acf-load_field/

    Cheers

  • In that case, you might wanna have an either/or meta query. Because if you just use NOT EXISTS, it’s going to include those that you checked and uncheck (which the featured_post is 0, but still consider “exists”)

    
    $meta_query[] = [
        'relation' => 'OR',
        [
            'key' => 'featured_post',
            'compare' => 'NOT EXISTS'
        ],
        [
            'key' => 'featured_post',
            'value' => '1',
            'compare' => '!='
        ],
    ];
    

    Cheers

  • Based on that dump url, seems like your $map[‘location’] is false, therefore the ‘q’ parameter is not being added.

    Also weird that your key is 0. How did you defined your MyKey?

    try do a var_dump($map) and see if acf actually returns any value.

    I just tried it too, the code seems to work for me.

    Cheers

  • Oop, my bad, yeah i did missed a ‘)’. I’ve edited to the correct code.

    Can you double check the url that it’s generated? (do a var_dump($src); before your iframe).

    Can you also make sure the proper map services are enabled on that key? It doesn’t say in the google’s documentation, but i think you might also need to enable the “Google Places API Web Service” in order to use the place search.

    https://console.developers.google.com/apis/library/places-backend.googleapis.com/?filter=category:maps

    Cheers

  • The google map iframe link looks like the following:

    src="https://www.google.com/maps/embed/v1/place?key=YOUR_API_KEY&q=ADDRESS"

    https://developers.google.com/maps/documentation/embed/guide

    So, you can try:

    
    <?php
    $map = get_field('the_map_field');
    
    $src = esc_url(add_query_arg([
        'key' => YOUR_API_KEY,
        'q' => $map['address']
    ], 'https://www.google.com/maps/embed/v1/place'));
    ?>
    
    <iframe
      width="600"
      height="450"
      frameborder="0" style="border:0"
      src="<?php echo $src; ?>" allowfullscreen>
    </iframe>
    

    Cheers

  • can you clarify a bit on what do you mean by “clear the old values”?
    do you mean, don’t populate the previously saved values?

    if that’s the case, you can overwrite the “value” key.

    
    add_filter('acf/prepare_field/name=unique_field_name', 'acf_clear_saved_value');
    function acf_clear_saved_value($field) {
        $field['choices'] = YOUR_DYNAMIC_CHOICES;
    
        // flush/clear the saved value
        $field['value'] = null;
    
        // or, set it to whatever the default
        $field['value'] = $field['default_value'];
    
        return $field;
    }
    

    p.s. In order to “flush/clear” the value, your select field setting needs to have “allow null” enabled.

    Cheers

  • The selection is under the ‘choices’ key.

    
    function dynamic_dropdown_files( $field ){
        $something_dynamic = [
            'key_1' => 'value 1',
            'key_2' => 'value 2',
        ];
    
        $field['choices'] = $something_dynamic;
    
        return $field;
    }
    

    cheers

  • For 1) and 2)
    Are you restricted on old browser supports? cause i’d 100% suggest you just use the css columns to do that layout. it’s supported on all browser last 2 latest version now.
    http://caniuse.com/#search=column

    Example:

    
    <ul class="items">
        <?php while (have_rows('appetizers')): the_row(); ?>
            <li>
                <h4><?php the_sub_field('item'); ?></h4>
                <p><?php the_sub_field('desc'); ?>$<?php the_sub_field('price'); ?></p>  
            </li>
        <?php endwhile; ?>
    </ul>
    <style>
    .items {
        column-count: 2;
        column-gap: 20px;
    }
    </style>
    

    If you can’t or don’t wanna use the css way, this is a cleaner way to split them:

    
    <?php
        // get repeater values as array
        $appetizers = get_field('appetizers');
    
        // calculate how many items first
        $items_count = count($appetizers);
    
        // calculate how much half is, round up
        $items_half = ceil($items_count / 2);
    
        // split the repeater 
        $appetizers_chunks = array_chunk($appetizers, $items_half);
    ?>
    
    <div class="section">   
        <div class="secthead"><?php the_title( '<h2>', '</h2>' ); ?></div>
    
        <?php foreach ($appetizers_chunks as $chunk): ?>
            <div class="items">
                <ul>
                    <?php foreach ($chunk as $value): ?>
                        <li>
                            <h4><?php echo $value['item']; ?></h4>
                            <p><?php echo $value['desc']; ?> $<?php echo $value['price']; ?></p>  
                        </li>
                    <?php endforeach; ?>
                </ul>
            </div>
        <?php endforeach; ?>
    </div>
    

    3) i’m not sure if i understand the question. Is your repeater field not already set on the category edit? where’s the repeater field at?

    Cheers

  • Assuming your “category” field is a taxonomy field and the return type is term_id. then you can try:

    
    $events = tribe_get_events(
            array(
                'eventDisplay'=>'upcoming',
                'posts_per_page'=>-1,
                'tax_query'=> array(
                    array(
                        'taxonomy' => 'tribe_events_cat',
                        'field' => 'term_id',
                        'terms' => get_field('your_category_field_name')
                    )
                )
       ) );
    
  • Documentation should be here:

    https://www.advancedcustomfields.com/resources/add_sub_row/

    So, you need to know your flex-content fields’ field name too.

    For example, if your field_name is ‘page_blocks’, you’d do something like:

    
    foreach ($config as $index => $field) {
        foreach ($field['subfields'] as $key => $value) {
            add_sub_row(array('page_blocks', $index, $key), $value);
        }
    }
    

    p.s i haven’t tested yet.

    Cheers

  • This is how the acf added the language for options:
    \api\api-helpers.php:3027

    	    
        // append language code
        if( $post_id == 'options' ) {
            $dl = acf_get_setting('default_language');
            $cl = acf_get_setting('current_language');
        
            if( $cl && $cl !== $dl ) {
                $post_id .= '_' . $cl;
            }    
        }
    

    Basically, acf should automatically resolve if you just pass the ‘options’. However, if you were to update the value in a different language than you are currently on, you can temporarily switch acf’s current language setting.

    For example, if your site’s default language is English. But you are currently in French and try to update the English’s field value, you can:

    
    // store the currently language temporarily
    $real_language = acf_get_setting('current_language');
    
    // trick acf to the language you want
    acf_update_setting('current_language', 'en');
    update_field('field_name', 'some value', 'options');
    
    // switch it back
    acf_update_setting('current_language', $real_language);
    

    I haven’t tested yet, but, should work…

    Cheers

  • You can construct a custom array after the sorted array.

    
    ... 
    array_multisort( $order, SORT_DESC, $repeater );
    
    $actual_loop = [];
    
    foreach ($repeater as $row) {
        // if this is a new date, we create a new array item
        if (! isset($actual_loop[$row['date']])) {
            $actual_loop[$row['date']] = [
                'date' => $row['date'],
                'rows' => []
            ];
        }
    
        $actual_loop[$row['date']]['rows'][] = $row;
    }
    
    foreach ($actual_loop as $loop) {
        echo '<h3>' . $loop['date'] . '<h3>';
        ecoh '<ul>';
    
        foreach ($loop['rows'] as $row) {
            echo "<li>{$row['actividad']}. {$row['aula']}. {$row['hora_de_inicio']} - {$row['hora_de_fin']}</li>";
        }
    
        echo '</ul>';
    }
    

    Cheers

  • Assuming your field ‘latest_news’ is taxonomy field with single selection and returning the term object.

    the ‘category_name’ is actually not name, it’s the slug. (i know… it’s confusing :/)
    https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters

    So, you query should be:

    
    $category = get_field('latest_news'); // change your variable name so it doesn't confuse yourself
    
    $posts = get_posts(array(
        'posts_per_page'  => 2,
        'post_type'     => 'post',
        'category_name' => $category->slug, // this is using slug, not name
        'cat' => $category->term_id // or you can do this instead
    ));
    

    Cheers

  • you’d need to call on the $query object to modify it, it should look something like this:

    
    function exclude_featured_post( $query ) {
        if ( $query->is_home() && $query->is_main_query()) {
            // in case for some reason there's already a meta query set from other plugin
            $meta_query = $query->get('meta_query')? : [];
    
            // append yours
            $meta_query[] = [
                'key' => 'featured_post',
                'value' => '1',
                'compare' => '!='
            ];
    
            $query->set('meta_query', $meta_query);
        }
    }
    add_action( 'pre_get_posts', 'exclude_featured_post' );
    

    Cheers

  • You can use the prepare_field filter for that:

    
    <?php
    
    add_filter('acf/prepare_field/type=select', 'add_that_all_option');
    function add_that_all_option($field) {
        if (strpos($field['wrapper']['class'], 'acf-need-to-add-all-option') === false) {
            return $field;
        }
    
        $field['choices'] = array_merge(['' => 'All'], $field['choices']);
    
        return $field;
    }
    

    Note that acf/prepare_field/type=select filter will affect all the select field. That’s why the function first check if the field has the class ‘acf-need-to-add-all-option’ (you can rename it to whatever you want). So, the ‘All’ choices will only be prepend if you added the class in the field setting.

    If this thing only needs to happen to 1 field, you can use these filters instead:
    acf/prepare_field/name=YOUR_FIELD_NAME or acf/prepare_field/key=YOUR_FIELD_KEY

    https://www.advancedcustomfields.com/resources/acf-prepare_field/

    Cheers

Viewing 25 posts - 26 through 50 (of 66 total)