Update Custom fields 30 Days after - wordpress

I am having trouble finding a solution. I am using ACF5.
I would like a field to automatically change its value 7 days after the post author has chosen a value.
I am using a select field (Featured) with 2 values (Featured, Not Featured).
If you have a solution with a different type a field that would work too.
I found this https://wordpress.stackexchange.com/a/85606/124674 However, I do not know how to to use it.
Your help is greatly appreciated.

In order to do so you need two things:
a) you need to know when user modified that field.
Therefore you have to add some modified date field where you put a timestamp of last change of the featured field. Additionally if you have a lot of posts you may have a user_modified field "flag" to mark specific entries as needing attention.
b) you need to have a cron task which runs every minute / hour
This task would scan the wp_postmeta table in certain time intervals. When it finds the field which was modified by user and the modification date is older than XX days then you switch the value to the desired one.
I know that this is an overall overview and you still have a lot of small tiny details to figure out but those depend on your scenario.

Related

Firestore data model that can filter by 'not contains' or similar [duplicate]

This is the current sample structure
Posts(Collection)
- post1Id : {
viewCount : 100,
likes : 45,
points : 190,
title : "Title",
postType : image/video
url : FileUrl,
createdOn : Timestamp,
createdBy : user20Id,
userName : name,
profilePic: url
}
Users(Collection)
- user1Id(Document):{
postsCount : 10,
userName : name,
profilePic : url
}
viewed(Collection)
- post1Id(Document):{
viewedTime : ""
}
- user2Id(Document)
The End goal is
I need to getPosts that the current user did not view and in points field descending order with paging.
What are the possible optimal solutions(like changing structure, cloud functions, multiple queries from client-side)?
I'm working on a solution to show trending posts and eliminate posts that are already seen by users or poor content. It's really painful to deal with two queries especially when the user base is increasing.
It's difficult to maintain the "viewed" collection and filter the new posts. Imagine having 1 million viewed posts and then filter for the un-seen posts.
So I figured a solution, which is not that great, but still cool.
So here is our data structure
posts(Collection)
--postid(document)
Title.
Description.
Image.
timestamp.
priority
This is a simple post structure with basic details. You can see I have added a Priority field. This field will do the magic.
How to use Priority.
We should query the posts that start with the higher priority and ends with lower priority.
When a user posts a new Post. Assign the current timestamp as the default priority.
When the user upvotes (Likes) a post increase the priority by 1 minute(60000 milliseconds)
When the user downvotes (Dislike) a post decrease the priority by 1 minute (60000 ms)
You can reset the priority every 24 hours. If you start browsing the feed today morning you will see posts with the last 24 hours in past. Once the 24-hour duration reached you can reset the priority to the present time. The 24-hour limit can be changed according to your needs. You may want to reset the limit every 15 min. because in every 15 min 100s of new posts might have added. This limit will ensure the repetition of content in the feed.
So when you start scrolling the feed you will get all the trending posts first then lower priority posts later. If you post a post today and people start upvoting it. It will get an increased lifetime, thus overpowers the poor content and when you downvote it, it will push down the post as long as users will not reach it.
Using timestamp as a priority because the old posts should lose priority with time. Even the trending posts today should lose the priority tomorrow.
Things to consider:
The lifetime can vary according to your needs.
The bigger the user base. You should lower the lifetime value. because if a post posted today is upvoted by 10,000 users it trends 6.9 days in the future. And if there are more than 100 posts that have been upvoted by more than 10,000 users then you will never get to see a new post in those 6.9 days.
So a trending post should hardly last a day or two.
So in this case you can give 10 seconds lifetime, it will give 1.1 day lifetime for 10,000 upvotes.
This is not a perfect solution but it may help you get started.
Edit: 11th June 2021
Nowadays, there are two more options that can help you solve such a problem. The first one would be the whereNotEqualTo method and the second one would be whereNotIn. You might choose one, or the other according to your needs.
Seeing your database structure, I can say you're almost there. According to your comment, you are hosting under the following reference:
Users(Collection) -> userId(Document) -> viewed(Collection)
As documents, all the posts a user has seen and you want to get all the post that the user hasn't seen. Because there is no != (not equal to) operator in Firestore nor a arrayNotContains() function, the only option that you have is to create an extra database call for each post that you want to display and check if that particular post is already seen or not.
To achieve this, first you need to add another property under your post object named postId, which will hold as String the actual post id. Now everytime you want to display the new posts, you should check if the post id already exist in viewed collection or not. If it dons't exist, display that post in your desired view, otherwise don't. That's it.
Edit: According to your comments:
So, for the first post to appear, it needs two Server calls.
Yes, for the first post to appear, two database calls are need, one to get post and second to see if it was or not seen.
large number of server calls to get the first post.
No, only two calls, as explained above.
Am I seeing it the wrong way
No, this is how NoSQL database work.
or there is no other efficient way?
Not I'm aware of. There is another option that will work but only for apps that have limited number of users and limited number of post views. This option would be to store the user id within an array in each post object and everytime you want to display a post, you only need to check if that user id exist or not in that array.
But if a post can be viewd by millions of users, storing millions of ids within an array is not a good option because the problem in this case is that the documents have limits. So there are some limits when it comes to how much data you can put into a document. According to the official documentation regarding usage and limits:
Maximum size for a document: 1 MiB (1,048,576 bytes)
As you can see, you are limited to 1 MiB total of data in a single document. So you cannot store pretty much everything in a document.

Predefine WordPress publication time and time

I'm just looking for a solution that will enter predefined date and time to every new post's editing window.
Due to some peculiarities of my site the post time should always be the same, only the dates may vary. But sometimes I have to add lots of posts bearing the same year and month and differ only by the date.
So the best solution would be to set desired fixed date and time for every new post, so that I could only edit the date if needed.
This would save my time greatly.
No matter if it would be a plugin or a functions.php code. But functions.php is preferred if it is able to interact with the backend.
Have you tried Automatic Post Date Filler? It includes a JavaScript based solution as I suggested in comments earlier, packed in a plugin with some options. Does this satisfy your needs?

How can I display Wordpress posts in a repeatable random order?

I would like to control the MySQL statement that Wordpress uses to give me a group of posts. Specifically, I would like to add this to the sql:
ORDER BY RAND(CURDATE())
This particular implementation has a fixed number of posts that will not be changing. However that would be boring for returning visitors and some posts that are down the page would likely never be seen. I would like to display the posts in a random order that is the same all day and then gets randomized differently the next day.
WP_Query allows for a rand function but it effectively does:
ORDER BY RAND()
The problem this causes me is that it randomizes differently each time it is queried. I want it to stay the same for every query all day. Seeding the randomizer with today's date accomplishes this. WP_Query however does not allow for seeding the randomizer. So how do I accomplish my desired end?

Writing the correct formula for SugarCRM

I am trying to automatically populate a field through a calculated field.
Just a quick background we distribute equipment with serials numbers. This equipment is sometimes returned. So some customers have multiple products each with different status of returned, shipped and installed.
I would like to transfer this serial number to a field on the contact through a calculated field only if the status is installed or shipped.
I have tried:
related($products,"serial"),",",(related($products,"status"))
and
related(contains(status,"installed)"products,"serial")
I need this for reporting reasons and would be greatly appreciated if you could help.
Thanks
You need a combination of ifElse and equal and related and or
As an example, the following Sugar Logic formula can be placed on a Contact record and will populate the field with the related account's name if the related account is of the type "Reseller." If the Account is of some other account_type then the field takes the value of "nope!"
ifElse(equal(related($accounts,"account_type"),"Reseller"),related($accounts,"name"),"nope!")
If you wanted to add another condition, or allow for another acceptable Account Type, build in an or
When you're writing lengthy Sugar Logic like this, I find it helpful to start writing it out with indentation using a text editor:
ifElse(
or(
equal(related($accounts,"account_type"),"Reseller"),
equal(related($accounts,"account_type"),"Investor"),
),
related($accounts,"name"),
"nope!"
)
In some versions of Sugar I've had to remove the extra spacing but it seems like in 7.2.2.0 at least the editor actually allows and preservers the formatting, which is a pleasant surprise.

Ubercart - Chosen Delivery Date to limit Shipping Options?

On the check out page I need users to choose a delivery date. Their needs to be multiple shipping options (that cost different amounts), but these are restricted based on what day you choose. Alternately if you choose a shipping method first, this will restrict what days you can choose for delivery.
One shipping option is ‘saturday’, and the delivery date must be a saturday.
Another shipping option is ‘next day’, the delivery must be the next day, and the order must be made before 2pm.
The final option is 'standard', which has no limitations except it cant be delivered on a saturday, and the delivery cant be the next day.
Also, I need to be able to restrict dates for delivery for all shipping options, as deliveries wont be made on bank holidays or the day after.
Im really struggling to do this so Id appreciate any pointers. If I can only achieve some of what I need that may be ok as a compromise.
Thanks
This sounds like a perfect case for using a calendar table to identify which dates are actually holidays. While I don't have specific experience with Ubercart, I've used calendar tables in a number of different solutions, and even wrote up a blog entry that details how to create and use a calendar table with a MySQL server. It's quite long, so rather than post the whole thing here, I'll just point you to the actual entry at http://www.brianshowalter.com/calendar_tables.

Resources