Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the community forum?
All Topics
admincolumnspro

Filtering (and sorting) custom column

Hello,

I’m trying to figure out how to filter (also sort) a custom column that I created from the custom column starter kit code. I saw in the acp-column-column_name.php file the section for sorting, but was unsuccessful in getting that to work properly, and I have not seen any documentation on getting filtering to work for a custom column. The return value is a simple string.

Thank you,
Paul

5 months ago
Stefan
Developer

Hi Paul,

We left Filtering intentionally out of the toolkit because that logic is more complex than the other.
Besides that, we have two filter options at this moment (Filtering and Smart Filtering) and we’re not really sure if we’re going to keep the old filtering method or that it will completely be replaced by the newer Smart Filtering feature. I’ll have another look if it will be useful to add a Smart Filtering example to the toolkit as well, but that may take some time. In the meantime, could you tell me a bit more about your column? Does it display meta data or related data? Maybe you can send me an email at support@admincolumns.com with what you have so far so I can do a quick review for you.

5 months ago
admincolumnspro

Hey Stefan. Thanks for your reply.

It is meta data. It is very simple, so I’m just going to include what it is in get_raw_value() here:

$nabe=get_post_meta($post_id,”address_neighborhood”,true);
$muni_id=get_post_meta($nabe,”neighborhood_municipality”,true);
$muni_name=get_the_title($muni_id);
return $muni_name;

So that returns the right data, and now we would just like to sort / filter the returned result.

Thank you,
Paul

5 months ago
admincolumnspro

Hi Stefan – This seems to have gone quiet – can you please point me in the right direction here?

Thanks

4 months, 2 weeks ago
Stefan
Developer

Hi Paul, sorry for the late response.

Based on your raw value I suspect that you’re trying to fetch data from another post type that contains the data that you’re actually showing. Is that correct? You’ll have to do three queries before you do the actual get_the_title(). so I’m afraid it’s not that easy to write your logic for both filtering and sorting.

For sorting it is possible to do it the easy way and just load the Sorting model that just sorts on the column value, but since retrieving your value already requires 4 queries, this will really have an impact on your performance when you have a lot of posts to sort on. You could try it by returning the following model in your pro column

public function sorting(){
return new ACP\Sorting\Model\Value( $this );
}

About filtering. Did you already figure out how you could filter your posts by altering the WP_Query on the post? Please notice that you need to manipulate the query when you want to filter and I can’t help you with this part. You probably want to use the pre_get_posts hook and see if you’re able to filter your overview in a sandbox. If you found a way to do that, then you can try to move that logic to a so-called Filtering model for our plugin. I can help you with that, but I suspect that finding the right way to alter the query is already quite challenging.

You can find more information about altering the query on this WordPress documentation page.
https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts

If you really want to change the SQL, you could have a look at this hook
https://codex.wordpress.org/Plugin_API/Filter_Reference/posts_clauses

And of course, have a look at our Filtering models in /classes/Filtering/Models/

4 months, 2 weeks ago

You must be logged in to reply to this topic.