Support

Account

Forum Replies Created

  • Hi,

    I received an email that tell that the user Feyfey answered my thread, however for a weird reason, I can’t see the post here.

    For my first question, I presume it was ok to said that ACF finally asigned an empty string (and not a null value) in the meta key. Maybe it happens when entering and removing a date manually in the field, then save the post. However I haven’t been able to make work the “NOT EXISTS” comparasion yet.

    For my second one, here’s finally a group of arguments which worked for me :

       $date_limit = date('Y-m-d', strtotime("-3 days"));
        $args = array(
            'post_type'      => 'vehicle',
            'meta_key'       => 'date_sell',
            'meta_query'     => array(
                'relation' => 'OR',
                array(
                    'key' => 'date_sell',
                    'compare' => '>=',
                    'value' => $date_limit,
                    'type' => 'DATE'
                ),
                array(
                    'key' => 'date_sell',
                    'compare' => '=',
                    'value' => ''
                )
            )
        );

    So with a Date type and ‘Y-m-d’ format.

    Hope it’ll help.

    Nox

  • I found the problem and resolved it.

    I was using a plugin which re-order the post-type I tried to call.
    This plugin is called Reorder-Post-Type.
    It seems to apply a filter on all queries that concerns a post-type affected by the plugin, even in your own code.

    If you want to prevent that, there’s a parameter that you can add in your query args, called ignore_custom_sort => true, like this :

        $args = array(
            'posts_per_page' => -1,
            'post_type' => 'post',
            'order' => 'DESC',
            'ignore_custom_sort' => true,
            'meta_key' => 'your_custom_field',
            'orderby' => 'meta_value'
        );
  • I forgot to reply my own post. I find the issue and the resolution. I post it if anyone ever has the same problem.

    Actually, I was using a re-order plugin on the post-type I tried to query, called Post-Types-Order.
    This plugin seems to automaticaly apply a filter for all queries that are pointed the re-ordered post-type. Even in your own code.

    There’s a way to prevent that in the API, by adding a parameter in the query args :

    ignore_custom_sort' => true

    You can find an example here : https://www.nsp-code.com/advanced-post-types-order-api/sample-usage/ (Don’t need to get advanced version to use it).

  • If I well understand, the “Name” comes from a field filled by the user in the same time he changes the value.

    I don’t know what is your trigger (a classic save button ? an Ajax request ?), but I presume that you can first use the “acf_update_value” filter to register the new Name, after what you can call your current custom function and bring the Name with get_field('name', $post_id). ($post_id is already set as a parameter in your custom function).

  • Hi,

    Actually, this isn’t an ACF issue. You need to add this file type to the list of WordPress mime types which are allowed for upload. You can find the default allowed types here : https://codex.wordpress.org/Function_Reference/get_allowed_mime_types

    To add your own to the list, you can take a look at this tutorial : https://www.wpbeginner.com/wp-tutorials/how-to-add-additional-file-types-to-be-uploaded-in-wordpress/

  • Hi,

    I tried to order my custom post-type (called “vehicle”) by a custom date field I created, called “date_sell”. I tried different ways (with “meta_value” and “meta_value_num” as “orderby” value), but none of them has worked. Here’s the simpliest code I tried to find the problem.

    Simple function :

    function eai_get_sold_vehicles_by_year($year){

    $args = array(
    ‘posts_per_page’ => -1,
    ‘post_type’ => ‘vehicle’,
    ‘order’ => ‘DESC’,
    ‘meta_key’ => ‘date_sell’,
    ‘orderby’ => ‘meta_value_num’, // also tried with ‘meta_value’
    ‘meta_query’ => array(
    ‘relation’ => ‘AND’,
    array(
    ‘key’ => ‘date_sell’,
    ‘value’ => array(”),
    ‘compare’ => ‘NOT IN’
    ),
    array(
    ‘key’ => ‘date_sell’,
    ‘value’ => ($year + 1) . ‘0101’,
    ‘compare’ => ‘<‘
    ),
    array(
    ‘key’ => ‘date_sell’,
    ‘value’ => $year . ‘0101’,
    ‘compare’ => ‘>=’
    ),
    array(
    ‘key’ => ‘price_sell’,
    ‘value’ => array(”),
    ‘compare’ => ‘NOT IN’
    )
    )
    );

    $query = new WP_Query($args);

    if($query->have_posts()) : while ($query->have_posts() ) : $query->the_post();
    echo ” . get_field(“date_sell”);
    endwhile;
    endif;

    }

    Return :

    23/12/2018
    24/10/2018
    07/10/2018
    09/12/2018
    12/11/2018

    Here the vehicles are listed as they come in the post-type list, so with the default behaviour, ordered by date of publication.

    I’ve searched on other threads, but I still can’t find what I did wrong here.
    Can someone please help me on this ?

    Thank you in advance,

    N.

  • Finally find a “bad” way to fix it.
    This is for a client, I couldn’t wait so long…

    I duplicated the fields group, and deleted the first one.

    I had difficulty understanding the way of ACF works in the database, I was looking for the rules links, but there’s a lot of wp_meta keys which have been created. Fortunately (and a bit oddly) the duplicated group keep all the content which has been written on the different pages in the previous fields group, so It works now.

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