Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>$columns that is being passed to your function my_edit_product_columns is an array of all of the existing columns. You can replace the entire thing or use any standard array manipulation to change the columns &amp; column order. </p> <p>For example, if you wanted to specify the columns you would do something like (taken from an events custom post type I use):</p> <pre><code>$columns = array( "cb" =&gt; "&lt;input type=\"checkbox\" /&gt;", "title" =&gt; "Event Name", "event_date" =&gt; "Date", "start_time"=&gt;"Time", ); </code></pre> <p>So if you simply print_r($columns) to see what it currently has, you could manually reorder it. </p> <p>To insert your column at a specific position in the existing $columns array use:</p> <pre><code># Insert at offset 2 $offset = 2; $newArray = array_slice($columns, 0, $offset, true) + array('new_column_id' =&gt; 'New Column Name') + array_slice($columns, $offset, NULL, true); </code></pre> <p>See this thread for more on that: <a href="https://stackoverflow.com/questions/1783089/array-splice-for-associative-arrays">array_splice() for associative arrays</a></p> <p>//ADDED</p> <p>I just tested this out locally on a custom post type I have in use called products. This code works fine for me. The offset starts with column 1, so to make my new column be the second one, I set offset at 2.</p> <pre><code> public function productsListColumns($columns){ $columns = array( "cb" =&gt; "&lt;input type=\"checkbox\" /&gt;", "title" =&gt; "Product", "price" =&gt; "Price" ); $offset = 2; $newArray = array_slice($columns, 0, $offset, true) + array('new_column_id' =&gt; 'New Column Name') + array_slice($columns, $offset, NULL, true); return $newArray; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload