In wordpress, I call a WP_Query. For each post found, I add a key+value row to a PHP array.
$array[$key] = $value;
The key is a timestamp, the value a string. Here comes the problem. In order to use a jQuery calendar, I need to get a JSON object as follows :
var codropsEvents = {
'11-23-2015' : 'text',
'11-23-2015' : 'text two',
'11-20-2015' : 'some other text',
'11-19-2015' : 'Anything that is text'
};
To do this, the json_encode() function almost works.
The thing is, PHP doesn't allow to use the same key in multiple rows : if I have multiple posts with the same timestamp (a wp meta value), PHP only stores one in the array.
My calendar therefore displays only one post per day.
How can I organize my PHP array in order to get the good format of the JSON object?
** /!\ UPDATE /!\ **
In fact, I don't need multiple rows with the same key. For every post with the same timestamp, I need to create a row with a unique key (the timestamp) and a unique value which will be a string containing all the posts titles.
Hope I'm clear.
array_push($array, array($date => 'value'));But json_encode returns an object of multiple objects containing one row each.