Support

Search results for ""

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

Upgrade Existing Code for Filter in List?

You’ve helped me with the following code (below). It no longer works to re-map the display (ie: lookup the ID’s in each row of the Session List, and instead, display the speaker name). Any ideas on how to fix this?

/**
* @param array $args
* @param AC\Column $column
*
* @return array
*/
function wwdvc_filter_format_unserialize_options( $args, AC\Column $column ) {
if( $column instanceof AC\Column\CustomField && ‘session_speakers_list’ === $column->get_meta_key()
){

# grab all speaker IDs for faster processing
$speaker_posts = get_posts(array(
‘numberposts’ => -1, // get all posts.
‘post_type’ => ‘speaker’,
‘post_status’ => ‘any’,
));

$speaker_lookup = wp_list_pluck( $speaker_posts, ‘post_title’, ‘ID’ );

foreach ( $args[‘options’] as $value => $label ) {
$speakers = unserialize( $value );
$match = array();
foreach($speakers as $idx) {
array_push($match, $speaker_lookup[$idx]);
}
$args[‘options’][ $value ] = implode(‘,’,$match);
}
}

return $args;
}

add_filter( ‘acp/filtering/dropdown_args’, ‘wwdvc_filter_format_unserialize_options’, 10, 2 );

10 months, 3 weeks ago
Stefan van den Dungen Gronovius
Developer

Can you let me know what is not working anymore? We haven’t made any changes to the code’s hook, so there should be no reason why the hook is not being triggered. Are all the options in the dropdown menu still saved correctly, or are you seeing any error messages?

10 months, 2 weeks ago
Dan Linstedt

Hi Team,

It wasn’t your code – it was my choice of metadata field. BUT I do have a question…

The new “speakers” meta-field I went to apply is stored as follows:

meta_key = speakers
meta_value = [6956]

It’s a literal array (not a hash array, and not a serialized array) of ID values. Unfortunately your use of a POST TYPE that looks-up CSV array values, does not understand that this data is a standard array. So I’m now wondering can you add code / fix or adjust the existing code to check for a standard array instead of a simple CSV to lookup by post ID?

Thanks,
Dan

10 months, 2 weeks ago
Stefan van den Dungen Gronovius
Developer

Hi Dan,

If you store an array to the post meta field, it is still stored serialized in the database, because that is what WordPress automatically does when you store it using the update_post_meta methods.

In that case, when you loop over the $options in the arguments, What is the value that you are getting returned for $value? Is that not a serialized array?

I’m not really sure what you mean by the CSV array values and how this is related to this issue. Can you maybe contact me on support (support@admincolumns.com) with some screenshots of the values in the database and what you’ve got so far?

10 months, 2 weeks ago
Dan Linstedt

Hi Stefan,

It’s not my code that is storing this meta_value. the literal value in meta_value is: ‘[6956]’, so when it’s fetched – it is being fetched by Admin Columns Pro as a POST field, which the doc on the config page says (as you know), a comma list of values.

It doesn’t appear to understand the meta value, and that its not a serialized array but rather a literal value that has to be “converted to an array” by PHP call.

In other words: $returnValue = json_decode(‘[6956]’);
which properly returns a PHP array that can be processed.

*yes, if I need to, I can write my own code snippet to process the values, but I’m trying to avoid writing code.

Thoughts?
Dan

10 months, 2 weeks ago
Stefan van den Dungen Gronovius
Developer

In this case, writing your own hook/snippet is the only way to do that.
Even the date you had before (serialized) did not work out of the box and needed some custom code, so for this more uncommon value format, we don’t have any support. I don’t expect that we will support that format any time soon in our feature and display logic.

10 months, 2 weeks ago
Dan Linstedt

Hi Team,

I got the column display working by switching unserialize over to JSON_DECODE, now the speakers json based array stored as unserialzed text works, and displays the speakers names in the table / list.

I have one more question: is there a HOOK to change the Smart Filter (when the filter button is clicked) to: process CONTAINS?
I tried the smart filter and it puts the speaker name (which doesn’t match) in the contains. I need it to put the speaker post ID behind the scenes.

10 months, 2 weeks ago

You must be logged in to reply to this topic.