[Plugin: WP-Table Reloaded] Dynamic Data Sort on Post Title (not ID)
-
QUESTION
I have the first column of the table showing the Post Title and a hyperlink to the post:
<td class=”column-1″>ID) . ‘”>’ . $post->post_title . ‘</td>This links nicely, but when you click the column heading to SORT, it sorts on the ID, rather than the post_title. It picks up the first information in the cell to sort.
==========================================
ANSWER
Well, it does not really sort by the ID, but more by the resulting HTML
output.Your PHP from above will result in the HTML (e.g.)
Northern
Experience
inside a cell.
The sorting script doesn’t know that this is a link and that it should
sort by the text. Instead it treats this as a simple string, which is
sorted from left to right. And with that, the URL (which contains the ID at
the place that distinguishes the URLs) is the deciding sort criterion.
Thus, you’ll need to “fake” this, for example by adding the Post Title
again *before* the link, so that it is not visible.
You could do this with an invisible span, like
<span style=”display:none;”>POST TITLE</span>Thus, if you change your code above to
<td class=”column-1″><span style=”display:none;”>’ . $post->post_title .
‘</span>ID) . ‘”>’ . $post->post_title .
‘</td>
it should work ??
============================
ANSWER – REVISED
actually I just found an even better solution.
Instead of that (actually ugly) <span> element, you could add the “title”
attribute to the link, before the “href”.
Like this:
My link text
would need to become
My link textIn your code this would be like this:
<td class=”column-1″>post_title . ‘” href=”‘ .
get_permalink($post->ID) . ‘”>’ . $post->post_title . ‘</td>
- The topic ‘[Plugin: WP-Table Reloaded] Dynamic Data Sort on Post Title (not ID)’ is closed to new replies.