Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
Orlando Marconi

Help with Array and User Metafield

Hello!

I have a user metafield that records the browsing history, I want to display the posts visited in the table.

My array is like this:

array (
  0 => 
  array (
    348 => 
    array (
      'visits' => 4,
      'time' => '2023-06-08 11:16:32',
      'last_time' => '2023-06-17 17:16:14',
    ),
    350 => 
    array (
      'visits' => 1,
      'time' => '2023-06-08 11:16:56',
      'last_time' => '2023-06-08 11:16:56',
    ),
    346 => 
    array (
      'visits' => 18,
      'time' => '2023-06-09 07:48:30',
      'last_time' => '2023-06-11 15:08:50',
    ),
  ),
)

Just pointing to this metafield the value looks like this inside the cell:

2, 2023-06-22 23:55:05, 2023-06-23 00:01:49

Would you help me?

1 year, 5 months ago
Orlando Marconi

Follow

1 year, 5 months ago
Orlando Marconi

I forgot to mention that the value that should appear is the CPT title and not the ID.

The ID in the array is this one in bold:

array (
0 =>
array (
348 =>
array (
‘visits’ => 4,
‘time’ => ‘2023-06-08 11:16:32’,
‘last_time’ => ‘2023-06-17 17:16:14’,
),
350 =>
array (
‘visits’ => 1,
‘time’ => ‘2023-06-08 11:16:56’,
‘last_time’ => ‘2023-06-08 11:16:56’,
),
346 =>
array (
‘visits’ => 18,
‘time’ => ‘2023-06-09 07:48:30’,
‘last_time’ => ‘2023-06-11 15:08:50’,
),
),
)

1 year, 5 months ago
Stefan van den Dungen Gronovius
Developer

Since your data is so specific, the only way to make something useful out of it is to write the value of that column yourself.
You could alter the value for your custom field with this hook:
https://github.com/codepress/admin-columns-hooks/blob/master/ac-column-value.php

Even better would be to write your own custom column.
Since you probably don’t need any filtering/sorting/editing support, you can use the default WordPress way to write your own column. ChatGPT might help you with this ;)

1 year, 5 months ago
Orlando Marconi

I hadn’t thought about GPT, I work 24/7 with it and I haven’t tried it! Do you have any tips on how to ask or will natural language suffice? Thanks for the idea.

1 year, 5 months ago
Stefan van den Dungen Gronovius
Developer

Prompt it with the fact that you would like to create a custom column for a (custom) post type admin table. Let it write the specific code for retrieving the value and then let it combine and improve the code. I was able to let it create a WordPress post type column that showed me some aggregated data.

1 year, 5 months ago

You must be logged in to reply to this topic.