Hot answers tagged

21

OK - in the end turned out to be fairly simple - as I'd had some kind of mental block - menu_order is a variable in the $post object (thanks to @brady for reminding me of that). @scribu's post on creating sortable column values then gives the rest. So, assuming the custom post type is called header_text, these are the functions and hooks that are needed: ...


10

I found a solution that works for me! I dropped this code in functions.php : add_action('admin_head', 'my_column_width'); function my_column_width() { echo '<style type="text/css">'; echo '.column-mycolumn { text-align: center; width:60px !important; overflow:hidden }'; echo '</style>'; }


9

here you go: <?php /* Plugin Name: ajaxed-status Plugin URI: http://en.bainternet.info Description: answer to : Custom column for changing post status via ajax http://wordpress.stackexchange.com/questions/33442/custom-column-for-changing-post-status-via-ajax Version: 1.0 Author: Bainternet Author URI: http://en.bainternet.info */ if ( ...


9

See the follow-up post: http://scribu.net/wordpress/sortable-taxonomy-columns.html


9

Changing admin columns belongs to a plugin, not to a theme file, because themes should never change anything else than frontend output. You can get the complete plugin here: Plugin Product Editor Column. Looking at the docs you linked to, I see the plugin author requires a child class that mixes multiple separate tasks. That’s not good. We will see in a ...


8

Here's how I recently added a custom taxonomy to the media library as a sortable column: // Add a new column add_filter('manage_media_columns', 'add_topic_column'); function add_topic_column($posts_columns) { $posts_columns['att_topic'] = _x('Topic', 'column name'); return $posts_columns; } // Register the column as sortable function ...


5

There are far better ways of doing this. Instead of modifying the user table, make use of User Meta. It has a dedicated table, and works the same way as post meta, but for users. add_user_meta get_user_meta update_user_meta There are many tutorials explaining how to add additional fields to the user profile using User meta to store them, and it's how a ...


5

Your problem is a simple typo: array($this, 'manage_post_columns', 10, 2) VS. array($this, 'manage_post_columns'), 10, 2 I guess you see the difference


5

It's because you are checking 'event_date' == $vars['event_date'] not 'event_date' == $vars['orderby]. But don't use the request filter. Instead: add_action( 'pre_get_posts', 'event_column_orderby' ); function event_column_orderby( $query ) { if( ! is_admin() ) return; $orderby = $query->get( 'orderby'); if( 'event_date' ...


5

1. Change post title in post list column I misunderstood what you wanted - obviously. You can do that like this: add_action( 'admin_head-edit.php', 'wpse152971_edit_post_change_title_in_list' ); function wpse152971_edit_post_change_title_in_list() { add_filter( 'the_title', 'wpse152971_construct_new_title', 100, ...


4

Changing the public argument of register_post_type() will remove the link to view your custom post type publicly. 'public' => false, See: WordPress Codex Note that this will also hide your custom post type from the admin navigation menus, which you might not want. To hide the 'View Post' link but keep your post type in the admin menus use show_ui as ...


4

You are using wrong number of arguments in add_filter, you specified to get 2 arguments and you are looking for third one: Update your add_filter code to this: add_filter( 'manage_post_tag_custom_column' , 'my_custom_column' , 10 , 3 ); The 3 in the end tells the filter to provide all the three arguments to your function.


4

You should be able to set the column width using CSS quite easily. You can use the .column-{name} class to apply styles to the column cells (both th and td). For example: .column-mycolumn { width:20%; } Make sure you don't have other styles overruling your column width because of CSS specificity rules. Also, long words without spaces or large images could ...


4

Thanks Nicusor: Works great. I was able to change the width of selected columns on the Posts panel (e.g Title, Author, Categories) with your solution as follows: add_action('admin_head', 'my_admin_column_width'); function my_admin_column_width() { echo '<style type="text/css"> .column-title { text-align: left; width:200px !important; ...


4

Here is an interesting approach: THE PLAN AND LOGIC: Custom fields are a build in functionality that will fit our needs perfectly. We can set a new custom field and then use that field to enter and store our custom data. We can then use a widget to display this custom content in the sidebar of our single pages Example of custom field in post editor ...


4

You can do this by hooking into the 'taxonomy'_edit_form and edited_'taxonomy' actions. add_action('taxonomy_edit_form', 'foo_render_extra_fields'); function foo_render_extra_fields(){ $term_id = $_GET['tag_ID']; $term = get_term_by('id', $term_id, 'taxonomy'); $meta = get_option("taxonomy_{$term_id}"); //Insert HTML and form elements here } ...


3

here is a modified version of your class that should work: class Add_Blog_ID { public static function init() { $class = __CLASS__ ; if ( empty( $GLOBALS[ $class ] ) ) $GLOBALS[ $class ] = new $class; } public function __construct() { add_filter( 'wpmu_blogs_columns', array( $this, 'get_id' ) ); ...


3

EDIT- this answer is old, there are better options. a few plugins - pods, magic fields, custom fields template. or you can DIY with some meta boxes and tinymce editors, see this answer.


3

The manage_{TAXONOMY}_custom_column filter hook passes 3 arguments: $content $column_name $term_id So try this: function add_book_place_column_content($content,$column_name,$term_id){ $term= get_term($term_id, 'book_place'); switch ($column_name) { case 'foo': //do your stuff here with $term or $term_id $content = ...


3

i did something similar with some radio buttons and a special taxonomy. i worked almost exclusively from the following 2 tutorials: http://shibashake.com/wordpress-theme/expand-the-wordpress-quick-edit-menu http://scribu.net/wordpress/sortable-taxonomy-columns.html though i was working with a taxonomy, the scribu tutorial actually links to another scribu ...


3

The problem is that by setting the posts to be ordered by _start_event_datetime you're creating the implicit assumption that the post will have that meta. This means the SQL query WordPress generates will only fetch posts of your custom post type with that meta. There are two possible solutions to this: Replace your current query with a slightly more ...


3

Solution from a cross post over at StackExchange from @birgire: The problem is that you run the clientarea_default_order callback too late. To fix that you only have to change the priority from the default one that's 10: add_action( 'pre_get_posts','clientarea_default_order'); to the priority of 9: add_action( ...


2

EDIT From the comments from the OP There's a few concerns though and suggestions on improvement. First of all, not sure if i missed something, but the list are not links? Second is that with this list it outputs a letter even though it doesn't have a post assigned to the letter..... and Posts that starts with an number won't be listed, would it ...


2

The filter is only applied to custom columns that are added by you (or plugins and themes), not the default columns. If you want to modify the output of all default columns, I think you may have to add your own columns and duplicate the functionality of the defaults, then unset the defaults via manage_users_columns, since not all of them have filters to let ...


2

You can try this solved your problems: add_action('admin_head', 'my_admin_custom_styles'); function my_admin_custom_styles() { $output_css = '<style type="text/css"> .column-date { display: none }; .column-tags { display: none }; .column-author { width:30px !important; overflow:hidden }; .column-categories { ...


2

You're looking for custom fields. Widgets are, generally, meant to be used for far more static content. Pages have custom fields enabled by default. You might not see them in the editor because I think they're also hidden by default. Click 'Screen Options' to make sure they're turned on. When you create the custom field, you'll give it a key and a value. ...


2

Yes you have to write a custom function and call it on your manage columns it will help you to get the necessary contents. public function xxxx_get_cpt_data($post_ID) { // $cpt_values = get_post_custom($post_ID); global $wpdb; $sql = "SELECT * FROM ". $wpdb->prefix. "custom_table WHERE post_ID=". ...


2

Yes, you need to write code to populate it. This is untested but should work. add_filter('manage_edit-cpt_roundtable_columns', 'init_roundtable_custom_columns'); function init_roundtable_custom_columns($columns) { return array( 'cb' => '<input type="checkbox" />', 'title' => __('Title'), 'taxonomy-sessions' => ...


2

I fixed this issue by changing some of my code. I changed: add_filter( 'request', 'timeline_column_orderby' ); function timeline_column_orderby( $vars ) { if ( !isset( $vars['orderby'] ) || ( isset( $vars['orderby'] ) && 'Year' == $vars['orderby'] ) ) { $vars = array_merge( $vars, array( 'meta_key' => ...


2

So, from what I can tell, you want four columns of relatively equal length on a page, with a title letter every time you move on to a new letter of the alphabet. <?php $num_cols = 4; // set the number of columns here $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; // for pagination $args = array( 'orderby' => 'title', 'order' => ...



Only top voted, non community-wiki answers of a minimum length are eligible