Custom Fields
Re-Envisioned
Support MB Views filter by date

  • Creator
    Topic
  • #29072
    Resolved rhs@mediastuff.com.ar
    Participant

    Hi, i need to display only post from actual day
    i´m trying this:

    {% set args = { post_type: 'licitacion', orderby: 'fecha_apertura', order:'asc', tax_query: [ { taxonomy: 'tipo-de-obra', field: 'slug', terms: 'obras-viales', } ] , meta_query: [ { key: 'fecha_apertura', value: 'date("Y-m-d")', compare: '=', type:'DATE' } ]} %}

    but don´t work. please, can help me with this? thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #29080
    Long Nguyen
    Moderator

    Hi,

    If you want to query posts by date, please use the argument date_query, read more in the documentation https://developer.wordpress.org/reference/classes/wp_query/#date-parameters

    And refer to this topic https://wordpress.stackexchange.com/questions/52070/how-to-get-posts-published-between-a-date-and-today

    Please note that: never use the PHP function in the View, you can run it via the proxy

    {% set my_date = mb.date("Y-m-d") %}

    then value: my_date,

    #29083

    Hi Long, i can make it work on VIEWS

    {% set fecha = "now"|date('Y-m-d') %}

    <h2>
    Mano de Obra, Materiales y/o Equipos
    </h2>
    {% set args = { post_type: 'licitacion', posts_per_page: 180, orderby: 'fecha_apertura', order:'asc', tax_query: [ { taxonomy: 'tipo-de-obra', field: 'slug', terms: 'mano-de-obra-materiales-y-o-equipos', } ], meta_query: [ { key: 'fecha_apertura', value:fecha , compare: '=', type:'DATE' } ] } %}

    {% set my_posts = mb.get_posts( args ) %}

    {% if my_posts == null %}
        Sin Licitaciones
    {% else %}
            {% for post in my_posts %}
                    &lt;h3&gt;{{ post.post_title }}&lt;/h3&gt;
                    Tipo de Obra: {{ mb.get_the_term_list( post.ID, 'tipo-de-obra' ) }}&lt;br&gt;
                    Comitente: {{ post.comitente }}&lt;br&gt;
                    Lugar: {{ mb.get_the_term_list( post.ID, 'lugar' ) }}&lt;br&gt;
                    Fecha de apertura: {{ post.fecha_apertura | date( 'd-m-Y' ) }}&lt;br&gt;
                    Presupuesto oficial: {{ post.presupuesto_oficial }} ({{ post.presupuesto_oficial_moneda }})&lt;br&gt;
            {% endfor %}    
    {% endif %}
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.