1

Hi!

I have just started programming in Wordpress with the ambition of creating something useful one day. But I've naturally run into problems right away, and now i have tried several solutions but im thinking im doing something fundamentally wrong since absolutely nothing is happening on my frontend (admin panel) though several alterations of the code.

Having created a plugin file with the following code:

/*
Plugin Name: Example Brand
Plugin URI: Example.com
Description: Lorum Ipsum
Author: Example Examplesson
Text Domain: Example location
*/
function crispynewcolumns( $columns ) {

    $columns = array(
        'title' => __('test title 1'),
    );
    return $columns;
}
add_filter( 'manage_cri_creator_posts_column' , 'crispynewcolumns' );

The function crispnewcolumns replaces the original 'title' with the string 'test title 1' in the custom post type "cri_creator".

Code for cri_creator:

{"name":"cri_creator","label":"Constructors","singular_label":"Constructor","description":"","public":"false","publicly_queryable":"true","show_ui":"true","show_in_nav_menus":"true","show_in_rest":"false","rest_base":"","has_archive":"false","has_archive_string":"","exclude_from_search":"true","capability_type":"post","hierarchical":"false","rewrite":"true","rewrite_slug":"","rewrite_withfront":"true","query_var":"true","query_var_slug":"","menu_position":"","show_in_menu":"true","show_in_menu_string":"","menu_icon":"","supports":["none"],"taxonomies":[],"labels":{"menu_name":"Constructor","all_items":"","add_new":"","add_new_item":"","edit_item":"","new_item":"","view_item":"","view_items":"","search_items":"","not_found":"","not_found_in_trash":"","parent_item_colon":"","featured_image":"","set_featured_image":"","remove_featured_image":"","use_featured_image":"","archives":"","insert_into_item":"","uploaded_to_this_item":"","filter_items_list":"","items_list_navigation":"","items_list":"","attributes":""},"custom_supports":""},"knark":

My Setup is a WAMP localhost with php 5.6.3.5.

Both the plugin, custom post type and custom fields (AFC) shows up, but i got stuck here on the column manipulation. Should be simple enough - anyone have any ideas?

  • 1
    OK, but what exactly are you trying to achieve? – Krzysiek Dróżdż Jun 8 '18 at 16:59
  • Hi! Krzysiek Dróżdż, my goal is to display custom field data (from AFC) in the admin columns on the custom post type later on. At the moment though im just trying to manipulate the title of standard one to say "test title 1". Can't even get that working at this moment, so i figured i will crash and burn if i do anything more advanced than that. – CnapBack Jun 8 '18 at 17:23
  • if that's a copy / paste of your code, you have a typo- the filter is manage_cri_creator_posts_columns, plural. – Milo Jun 8 '18 at 17:58
1

You have misspelled the filter name. There is an "s" lacking at the end. The correct is manage_cri_creator_posts_columns.

As a suggestion, I'd say that it is better to manipulate the existing array rather than creating a complete new one. Might not be your case, but its a good idea to avoid conflicting with other plugins that could be doing something in this very same filter.

So, for instance, just to change the title label, it would be better if you did:

function crispynewcolumns( $columns ) {

    $columns['title'] = __('test title 1');
    return $columns;

}
add_filter( 'manage_cri_creator_posts_columns' , 'crispynewcolumns' );

Hope it helped. Here is the link to the documentation: https://codex.wordpress.org/Plugin_API/Filter_Reference/manage_$post_type_posts_columns

  • Thanks a lot Leo! :) Managed to solve it now, the problem was a combination of: 1. The spelling mistake you described, and 2. I was not aware that i had to manually activate my own plugin, so my code was never even loaded. Palm touched face. – CnapBack Jun 9 '18 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.