Support

Search results for ""

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

Column of a Metadata Array

Dear Admin Column Team,

I am adding a column that recovers a metadata field which is an array. I need to set a type of column that allows me to select just one register of the array not the whole array.

Trying to solve this by myself I added a column by php snippet and then choose that value as a column on “Admin Columns”. I worked fine but that value it is not shortable on “AdminColumns”.

How can I choose a register of an array?

Thank you in advance

3 years, 4 months ago
Stefan van den Dungen Gronovius
Developer

In order to display the value, you can use this hook:
https://github.com/codepress/admin-columns-hooks/blob/master/ac-export-value.php

Or you could write your own column by using our toolkit
https://docs.admincolumns.com/article/21-how-to-create-my-own-column

Please note that our plugin does sort columns based on values in the database. So this means that is your data is stored serialized in the database, it is not possible to sort that column. You could write your own Sorting model and sort it with PHP but that requires you to first fetch all the data for all posts in order to sort, which can be quite a heavy operation.

3 years, 4 months ago
RAUL JAUREGUI

I installed the plugin, but I have not a new type of column when trying to create a new one. Do I have something after installing the plugin? I have the same type of columns than before

3 years, 4 months ago
RAUL JAUREGUI

Ok I am seeing that it is not just install and edit a column name… Sorry. I go to read those, any kind of help to make easiest it is welcome

3 years, 4 months ago
RAUL JAUREGUI

Looks too much for just the simple thing I need. I just need to make shortable a column by the value of the field number2 of a metadata.
‘my_metada’ [0]
‘my_metada’ [1]
The column must show the value of ‘my_metada’ [1] which I get to do that with this code:

add_action( ‘manage_my_cpt_posts_custom_column’, ‘my_cpt_table_content’, 10, 2 );

function my_cpt_table_content( $column_name, $post_id ) {
if ($column_name == ‘compartir’) {
$status = get_post_meta($post_id, ‘my_metada’, true);
echo $status[1][“value”];
}
}

But I don´t know how to make it shortable when I create a new column and choose this column ‘compartir’

3 years, 4 months ago
Stefan van den Dungen Gronovius
Developer

Sorry, but there is no out-of-the-box solution for this.
I believe your data is stored serialized and serialized data is not sortable in a database.
The workaround I mentioned before where you sort in PHP is possible, but you’ll need to write the code to do that yourself as you’re writing your own sorting logic. Please note that this custom sorting logic is quite advanced coding.

3 years, 4 months ago

You must be logged in to reply to this topic.