Title: [Plugin: SortTable Post] Patch to allow specifying title for meta fields
Last modified: August 20, 2016

---

# [Plugin: SortTable Post] Patch to allow specifying title for meta fields

 *  [JB Christy](https://wordpress.org/support/users/jbchristy/)
 * (@jbchristy)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-sorttable-post-patch-to-allow-specifying-title-for-meta-fields/)
 * _[ Moderator Note: Please post code or markup snippets between backticks or use
   the code button. Or better still – use the [pastebin](http://wordpress.pastebin.com/)]_
 * I really like the SortTable Post plugin! One of the reasons I chose this plugin
   was support for custom post types and meta properties. However, I was little 
   sad that the slug for meta properties is displayed to the user as the column 
   heading. So I modified the code to allow specifying meta=”field1|Title For Field
   1,field2|Title For Field 2″. I find this a very useful feature and I suspect 
   other users might too. Perhaps you’d consider adding the feature to the next 
   release of the plugin? If so, see the patch below (patch is relative to version
   4.2 of the plugin).
 * Thanks for a great plugin! Very handy!
 *     ```
       Index: sorttablepost.php
       ===================================================================
       --- sorttablepost.php	(revision 32)
       +++ sorttablepost.php	(working copy)
       @@ -102,8 +102,14 @@
        	if( !$opt_notitles == 'true' ) { echo '<th>Title</th>'; }
        	if( !$opt_nodates == 'true' ) { echo '<th>Date</th>'; }
        	if( !$opt_excerpts == '' ) { echo '<th>' . $opt_excerpts . '</th>'; }
       -	if( $opt_meta ) : foreach( $opt_meta as $key ) {
       -		echo '<th>' . $key . '</th>';
       +	if( $opt_meta ) : foreach( $opt_meta as &$key ) {
       +    list($field, $title) = explode('|', $key);
       +    if (!empty($title)) {
       +      echo '<th>' . sanitize_text_field($title) . '</th>';
       +      $key = $field;
       +    } else {
       +      echo '<th>' . $key . '</th>';
       +    }
        	} endif;
        	if( !$opt_nocats == 'true' ) { echo '<th>' . $catlabel . '</th>'; }
        	if( !$opt_notags == 'true' ) { echo '<th>' . $taglabel . '</th>'; }
       ```
   
 * [http://wordpress.org/extend/plugins/sorttable-post/](http://wordpress.org/extend/plugins/sorttable-post/)

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [polenisland](https://wordpress.org/support/users/polenisland/)
 * (@polenisland)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-sorttable-post-patch-to-allow-specifying-title-for-meta-fields/#post-2871623)
 * Hi JBChristy!
    Your contribution is quite interesting but do not get it to work
   100%. I changed the code of sorttablepost.php and the shortcode as you say. The
   custom titles of the headers is OK, but the custom fields parameters shows the
   first paramater in all columns. Do you know what happens? Could you help me? 
   I hope I expressed myself clearly.
 * Thank you very much!
 *  [polenisland](https://wordpress.org/support/users/polenisland/)
 * (@polenisland)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-sorttable-post-patch-to-allow-specifying-title-for-meta-fields/#post-2871624)
 * Sorry not the first paramaters in all columns, the last Custom Fields (Horas)
   shows the parameter of the penultimate (Cliente).
    If add other Custom Fields
   shows always the penultimate paramater.
 * This is my code:
 * `[sorttablepost type="solares" meta="sol-referencia|Referencia,sol-potencia|Potencia,
   sol-cliente|Cliente,sol-horas|Horas" nothumb="true" nodate="true" nocats="true"
   notags="true"]`
 *  Thread Starter [JB Christy](https://wordpress.org/support/users/jbchristy/)
 * (@jbchristy)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-sorttable-post-patch-to-allow-specifying-title-for-meta-fields/#post-2871630)
 * Hi, polenisland!
 * Can you provide a URL where I can see the behavior? Also, if you could post the
   section of code you modified showing your modifications, that would help. I didn’t
   author the plugin and I don’t much about the code, but I’ll try to take a look
   for you.
 * -JB
 *  [polenisland](https://wordpress.org/support/users/polenisland/)
 * (@polenisland)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-sorttable-post-patch-to-allow-specifying-title-for-meta-fields/#post-2871631)
 * Hi JBChristy.
    I don’t provide a URL because is an web aplication in a internal
   network.
 * Here is the code i modified in sorttablepost.php:
 * (Line 99)
 *     ```
       // Create table header row
       	echo '<table class="sortable" id="'. $opt_tableid .'"><tr>';
       	if( !$opt_nothumbs == 'true' ) { echo '<th class="sorttable_nosort"></th>'; }
       	if( !$opt_notitles == 'true' ) { echo '<th>Nombre</th>'; }
       	if( !$opt_nodates == 'true' ) { echo '<th>Date</th>'; }
       	if( !$opt_excerpts == '' ) { echo '<th>' . $opt_excerpts . '</th>'; }
       	if( $opt_meta ) : foreach( $opt_meta as &$key ) {
       	list($field, $title) = explode('|', $key);
       	if (!empty($title)) {
       	echo '<th>' . sanitize_text_field($title) . '</th>';
       	$key = $field;
       	} else {
       	echo '<th>' . $key . '</th>';
       	}
       	} endif;
       	if( !$opt_nocats == 'true' ) { echo '<th>' . $catlabel . '</th>'; }
       	if( !$opt_notags == 'true' ) { echo '<th>' . $taglabel . '</th>'; }
       	echo '</tr>';
       ```
   
 * And this is the code which i add in page to show the table:
 * `[sorttablepost id="tablasolares" type="solares" meta="sol-referencia|Ref.,sol-
   tecnologia|Tecnología,sol-cliente|Cliente,sol-localizacion|Loc.Geográf.,sol-potencia
   |Pot.Pta(mW),sol-lazos|Núm.Lazos,sol-area-colectores|Área Col.(m²),sol-tipo|Tipo
   Col.,sol-area-planta|Área Pta.(m²),sol-temperatura|Temp.Vap.(ºC),sol-presion|
   Pres.Vap.(bar),sol-almacenamiento|Alm.Térm.,sol-tipo-almacenamiento|Tipo Alm.,
   sol-horas|Horas Alm.,sol-fecha|Fecha Contrat.,a| ,a| " nothumb="true" nodate="
   true" nocats="true" notags="true"]`
 * If not add the `.,a| ,a| "` at the end of code, the “sol-fecha” show the same
   of “sol-horas”, but show two cells in blank at the end of the table.
 * I hope you can help me…
    Many many thanks for your interest.
 *  Thread Starter [JB Christy](https://wordpress.org/support/users/jbchristy/)
 * (@jbchristy)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-sorttable-post-patch-to-allow-specifying-title-for-meta-fields/#post-2871632)
 * Hi, polenisland!
 * I tried your shortcode on my system without the ‘,a| ,a| ‘ at the end. I don’t
   have your data, but my column headings look fine. And your source code looks 
   just like mine. I stepped through the code in the debugger and saw no problems.
 * Here’s the shortcode I used:
 *     ```
       [sorttablepost id="tablasolares" type="press" meta="sol-referencia|Ref.,sol-tecnologia|Tecnología,sol-cliente|Cliente,sol-localizacion|Loc.Geográf.,sol-potencia|Pot.Pta(mW),sol-lazos|Núm.Lazos,sol-area-colectores|Área Col.(m²),sol-tipo|Tipo Col.,sol-area-planta|Área Pta.(m²),sol-temperatura|Temp.Vap.(ºC),sol-presion|Pres.Vap.(bar),sol-almacenamiento|Alm.Térm.,sol-tipo-almacenamiento|Tipo Alm.,sol-horas|Horas Alm.,sol-fecha|Fecha Contrat." nothumb="true" nodate="true" nocats="true" notags="true"]
       ```
   
 * And here’s the HTML that was generated (formatted for easier reading):
 *     ```
       <table class="sortable" id="tablasolares">
         <tr>
           <th>Title</th>
           <th>Ref.</th>
           <th>Tecnología</th>
           <th>Cliente</th>
           <th>Loc.Geográf.</th>
           <th>Pot.Pta(mW)</th>
           <th>Núm.Lazos</th>
           <th>Área Col.(m²)</th>
           <th>Tipo Col.</th>
           <th>Área Pta.(m²)</th>
           <th>Temp.Vap.(ºC)</th>
           <th>Pres.Vap.(bar)</th>
           <th>Alm.Térm.</th>
           <th>Tipo Alm.</th>
           <th>Horas Alm.</th>
           <th>Fecha Contrat.</th>
         </tr>
       </table>
       ```
   
 * I’m sorry, but I don’t see the problem. The only thing I can think is maybe some
   un-printable character got in the meta list that prevented the explode() from
   recognizing the final | and it retained the previous value of $title. You might
   try deleting the last few columns (maybe from Tipo Alm. to the end) and retyping
   them.
 * Wish I could be more help, but I’m afraid I can’t reproduce your problem.
 *  [polenisland](https://wordpress.org/support/users/polenisland/)
 * (@polenisland)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-sorttable-post-patch-to-allow-specifying-title-for-meta-fields/#post-2871633)
 * Ok perfect, I’ll continue trying to find the error.
    Many thanks, Sincerely….
 *  [mschuyler](https://wordpress.org/support/users/mschuyler/)
 * (@mschuyler)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/plugin-sorttable-post-patch-to-allow-specifying-title-for-meta-fields/#post-2871665)
 * I am having nearly the same issue except one difference – every column is correct
   except for the last.
 * For example if my “field|title” is a|A,b|B,c|C – I enter the short code correctly
   but it displays as “a|A,b|B,b|C”.
 * Has anyone else ran into this problem? JB Christy or polenisland have you found
   a fix?
 *  [coneff](https://wordpress.org/support/users/coneff/)
 * (@coneff)
 * [13 years, 2 months ago](https://wordpress.org/support/topic/plugin-sorttable-post-patch-to-allow-specifying-title-for-meta-fields/#post-2871677)
 * Hi, it’s perfect idea, but i can’t find a bug in the code.
    Display:
 *     ```
       a|A b|B c|C
       1,a 1,b 1,b
       2,a 2,b 2,b
       3,a 3,b 3,b
       ```
   
 * I need:
 *     ```
       a|A b|B c|C
       1,a 1,b 1,c
       2,a 2,b 2,c
       3,a 3,b 3,c
       ```
   

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘[Plugin: SortTable Post] Patch to allow specifying title for meta fields’
is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/sorttable-post.svg)
 * [SortTable Post](https://wordpress.org/plugins/sorttable-post/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/sorttable-post/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/sorttable-post/)
 * [Active Topics](https://wordpress.org/support/plugin/sorttable-post/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/sorttable-post/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/sorttable-post/reviews/)

 * 8 replies
 * 4 participants
 * Last reply from: [coneff](https://wordpress.org/support/users/coneff/)
 * Last activity: [13 years, 2 months ago](https://wordpress.org/support/topic/plugin-sorttable-post-patch-to-allow-specifying-title-for-meta-fields/#post-2871677)
 * Status: not resolved