Actually, offering or accepting payment in these forums is against the rules. While I appreciate your willingness to pay, it is not necessary. I am rewarded by helping people here in ways that are independent of monetary reward.
While I “speak” PHP, I am no wizard. My “vocabulary” is limited, so I avoid writing code for people. I usually either rework existing code as I did for you, or just suggest in general terms a proper approach. While a PHP solution exists for what you want, it is better done with mySQL, which I don’t “speak” well at all. You basically would want to query for distinct entries in the meta_value column of the postmeta table where (meta_key = ‘citat’ or meta_key = ‘autor’) and where through various table joins, the associated post has a published date within the last week. I know better than to even try to put that in proper mySQL syntax, it would be nowhere close to correct. I know the logic is correct though.
While this can also be done in PHP, it is nowhere near as efficient as using mySQL. If the data volume is not too much, it can be a workable solution, and something I know how to do much better than with mySQL.
You first query for all posts within the last week instead of just one, simply by changing the posts per page to -1 instead of 1. If all posts in that category have these custom fields, there is no need to further qualify the query. If some posts do not qualify, you need to add in a meta_query array argument to limit posts returned to those with the required custom fields.
You then loop through the posts just as you might for an archive page, except instead of outputting the titles and permalinks, etc. you push each meta value into it’s related array collection of values, but before actually adding to the array, first check to see if the value is already in the array with in_array()
, in which case there is no need to push the value in again.
Once the arrays of unique values are collected, use join()
to splice the values together in a format that is suitable for output.