Support

Account

Home Forums General Issues Query relationship fields based on added date

Solving

Query relationship fields based on added date

  • Hey everyone. I created a custom post type called “People” and a relationship field linked shown in my default post type, to link different articles with “People” i created.

    How can i query “X People” in my homepage, based on the date they have been added to a post?

  • You cannot. There is nothing stored about when a post is added to a relationship field.

    It might be possible but you’d need to build some way of recording this information yourself. For example you could create an acf/save_post action that fires before ACF has saved new values (priority < 10). In this action you can compare the old value using get_field() with the new value looking in $_POST[‘acf’] and then somehow record when new values are added.

    And you’d need to figure out how to store that value show that it can be queried, and I thinking about that I can’t come up with anything that could be stored in a single query-able field.

  • Hey John thank you for the reply. I sort of knew that that might be impossible to do, but i ve been out of the game (ACF) and thought that maybe something changed 🙂

    Can I query relationship fields then based on the actual post date? It so, how

  • Do you mean the post date of the Person that is added in the relationship, yes and no.

    The problem is that the this post date is not part of the post where the relationship is. What you need to do is to get the post IDs only of for the related field and then run a query using this list of post IDs in the “post__in” argument of the query combined with a post_date query.

  • Sorry i was unclear. I meant the actual post date, not the Person custom post date.

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

You must be logged in to reply to this topic.