• Resolved da2handz

    (@da2handz)


    Hi

    This is a great Plugin! Thank you!
    I am referring to the following Topic:
    https://www.ads-software.com/support/topic/query-posts-with-date-as-custom-field/

    I am now at the point where I can see Post from a particular category with:
    Custom field:date & Post Title

    I would like to:
    Sort by custom field:date and only posts in the future from now.

    I read this other article, and they could make it work, but I am not good in coding…is there any possibility to make this happen?

    Thank you in forward.

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Aldo Latino

    (@aldolat)

    Hi,

    This is a great Plugin! Thank you!

    You are very welcome!

    I am referring to…

    Only to better understand your needs, you want to:

    1) display posts that have the custom field date;
    2) sort the resulting posts by the custom field date;
    2) display posts that will be published in the future from now.

    Is this what you want to do?

    Thread Starter da2handz

    (@da2handz)

    Thanks for your reply.
    Exactly!

    And if possible, but not a must:
    – change the date format (09.10.2019 instead 2019-10-09)
    – have the date and post title in the same row

    thank you!

    Plugin Author Aldo Latino

    (@aldolat)

    You can use this settings:

    1) In Getting posts > Get posts with this meta key, insert date;
    2) In Getting posts > Get posts with this post status, choose “Scheduled”;
    3) In Getting posts > Order posts by, choose Meta value.

    That’s it.

    Regarding the date format, it depends on how the date is stored in the database. The custom field value is a text, so this will be displayed in the form you have used.

    Regarding date and post title in the same row, you can try this CSS:

    .pis-custom-field {
    	float: left;
    }
    
    .pis-title {
    	margin-left: 65px;
    }

    You can paste it in the panel “Styles” > “Custom styles” of the widget.

    Let me know, please.

    Thread Starter da2handz

    (@da2handz)

    Hi There

    -> I am now that far:
    – Posts with custom date are in Order in the widget

    -It only works, if i have ‘Get posts with this post status, choose “Published”. (The date of the Post has nothing to do with the date I want the posts to appear in the widget) For Example: Yesterday i wrote and published a post about an event on November 11th -> The post title appears with date 2019-11-11.

    – If I don’t manually adjust the “Custom Field Value” with todays date, Post titles with custom date 2019-10-20 will still appear in the widget. Is there a possibility, that posts automatically disappear, when the set date passes?

    Plugin Author Aldo Latino

    (@aldolat)

    Hi @da2handz,

    -> I am now that far:
    – Posts with custom date are in Order in the widget

    Ok.

    -It only works, if i have ‘Get posts with this post status, choose “Published”. (The date of the Post has nothing to do with the date I want the posts to appear in the widget) For Example: Yesterday i wrote and published a post about an event on November 11th -> The post title appears with date 2019-11-11.

    If the posts are already published, obviously you have to choose “Published”. I understood that the posts were in a scheduled status. ??

    – If I don’t manually adjust the “Custom Field Value” with todays date, Post titles with custom date 2019-10-20 will still appear in the widget. Is there a possibility, that posts automatically disappear, when the set date passes?

    Currently you can’t, but I’m considering adding a new section where the user can choose a dynamic date, such as now. For example, show posts that have a date in the custom field that is in the future from now. I do not know when I can make this enhancement, but stay tuned.

    In the meantime, manually adjust the date accordingly.

    Plugin Author Aldo Latino

    (@aldolat)

    Hi @da2handz,
    in the next version of Posts in Sidebar you can use now instead of inserting a complete date, for example:

    Using now means that WordPress considers the current date, without the need of manually updating it. In the screenshot, this means that WordPress will get posts that have a custom field date where the value is greater than the today’s date, i.e. in the future.

    In the upcoming days I will publish this new version.

    Stay tuned!

    Plugin Author Aldo Latino

    (@aldolat)

    Hi @da2handz,
    I have just released the new version. You can update and test it.

    Only to recall your needs:
    – you have some posts, already published, that talk about upcoming events;
    – these posts have a custom field named date where the date of the event is stored;
    – the date of the event is in the future;
    – you want to display only the events that have the date – stored in the custom field – in the future compared to now.

    For this specific reason I added the possibility to use now in the field “Getting posts” > “Custom fields query” > “Custom field value”. The word now is a special text that is automatically converted (if used) into a formatted date and time.

    Take note that the word now will be converted into current date and time, using the format you have defined in your dashboard (see Settings > General > Date format and also Time format).

    This means that, if your stored custom field is in the same format as in WordPress Settings, the widget will display the posts as intended. For example, if you have

    WordPress Settings: 2019-11-10 10:56:18 (year-month-day hours:minutes:seconds)
    Stored value in custom field: same as above

    you will get posts correctly.

    But, if you have instead:

    WordPress Settings: November 10, 2019 10:56:18 (month in letter + day, year hour:minute:second)
    Stored value in custom field: 2019-11-10 10:56:18

    you will not get posts.

    In this second case, you won’t have to change WordPress setting for date and time. You can use a function to change how the plugin must handle date and time.
    For example:

    function change_posts_in_sidebar_now( $formatted_date, $widget_id ) {
    	if ( empty( $widget_id ) ) {
    		return;
    	}
    
    	if ( 'pis_posts_in_sidebar-2' === $widget_id ) {
    		$date_format    = 'Y-m-d H:i:s';
    		$local_timezone = get_option( 'gmt_offset' ) * HOUR_IN_SECONDS;
    		$now_timestamp  = time() + $local_timezone;
    		$formatted_date = date( $date_format, $now_timestamp );
    	}
    	return $formatted_date;
    }
    add_filter( 'cf_value_a1', 'change_posts_in_sidebar_now', 10, 2 );

    Only change the ID of the widget pis_posts_in_sidebar-2, if needed. You can get the ID of the widget looking in the Debugging panel of the widget admin.

    Let me know, please.

    Plugin Author Aldo Latino

    (@aldolat)

    Hello,
    since some months have passed from last reply, I close the thread. Feel free to reopen it or start a new one.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Order by date (future date) as custom field’ is closed to new replies.