Title: Custom Table
Last modified: February 26, 2021

---

# Custom Table

 *  Resolved [Fred Atkinson](https://wordpress.org/support/users/fatkinson/)
 * (@fatkinson)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/custom-table-6/)
 * Yannick,
 *  Is there any way to configure a Library Configuration so that only a limited
   number of randomly chosen links [from a particular category] are displayed?
 *  The idea is to put a shortcode on the main page so that a few random links are
   displayed as part of the content. They should be sorted by the ‘sortcode’ custom
   field so they appear in the correct order.
 *  Let’s say a 3×5 table is desired. It should then [very randomly] select fifteen
   links from the category, sort them by the ‘sortcode’ value, and then display 
   the Name linked to the URL of each record in the 3×5 table. And each time the
   page is reloaded, a different set of fifteen links should appear.
 *  Is this currently doable?
 *  Regards,
 *  Fred
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fcustom-table-6%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 15 replies - 1 through 15 (of 26 total)

1 [2](https://wordpress.org/support/topic/custom-table-6/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/custom-table-6/page/2/?output_format=md)

 *  Plugin Author [Yannick Lefebvre](https://wordpress.org/support/users/jackdewey/)
 * (@jackdewey)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/custom-table-6/#post-14108358)
 * Yes, mostly, except for the past that says to sort by the sortcode value. If 
   the links are randomly chosen, they will be not be displayed based on their sortcode
   value.
 *  Thread Starter [Fred Atkinson](https://wordpress.org/support/users/fatkinson/)
 * (@fatkinson)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/custom-table-6/#post-14108411)
 * It loses something without that capability.
    You have to be an amateur radio 
   operator to understand why it’s so important. I will see if I can figure out 
   how to do that table.
 *  Thread Starter [Fred Atkinson](https://wordpress.org/support/users/fatkinson/)
 * (@fatkinson)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/custom-table-6/#post-14108441)
 * Well, I pulled it off. Take a look!: [https://www.wb4aej.com/test/](https://www.wb4aej.com/test/)
   
   I will be putting that short code on my main page shortly.
    -  This reply was modified 5 years, 2 months ago by [Fred Atkinson](https://wordpress.org/support/users/fatkinson/).
 *  Thread Starter [Fred Atkinson](https://wordpress.org/support/users/fatkinson/)
 * (@fatkinson)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/custom-table-6/#post-14108453)
 * The only issue is that it always uses the first fifteen links.
    How do I make
   it select them randomly?
 *  Plugin Author [Yannick Lefebvre](https://wordpress.org/support/users/jackdewey/)
 * (@jackdewey)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/custom-table-6/#post-14108458)
 * As I said, if you make it take random links, they will also be ordered randomly.
 *  Thread Starter [Fred Atkinson](https://wordpress.org/support/users/fatkinson/)
 * (@fatkinson)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/custom-table-6/#post-14108477)
 * I understood that perfectly.
    But it is not displaying random links. It is displaying
   the first fifteen every time (not dynamic content).
 *  Plugin Author [Yannick Lefebvre](https://wordpress.org/support/users/jackdewey/)
 * (@jackdewey)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/custom-table-6/#post-14108484)
 * Right. If you leave the order method to anything other than random, then it will
   always take the first X items based on the sort method selected. If you want 
   dynamic content, you need to set the sort method to random, which will mean that
   the random items will not be ordered.
 * I will see what else I could do, but I can’t promise anything.
 *  Thread Starter [Fred Atkinson](https://wordpress.org/support/users/fatkinson/)
 * (@fatkinson)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/custom-table-6/#post-14108503)
 * Sorry, I didn’t see that Random option.
    It’s looking good now!
 *  Plugin Author [Yannick Lefebvre](https://wordpress.org/support/users/jackdewey/)
 * (@jackdewey)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/custom-table-6/#post-14108508)
 * So… do you need me to do anything on this or is this resolved?
 *  Thread Starter [Fred Atkinson](https://wordpress.org/support/users/fatkinson/)
 * (@fatkinson)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/custom-table-6/#post-14108544)
 * For the sake of discussion, let me explain the sort method I use.
    Amateur radio
   calls consist of a prefix (1 or 2 letters or one letter and a numeral; the prefix
   identifies the nation in which the station is licensed), the call district (1
   numeral) of the nation the station resides in, and the suffix (1 to 3 letters)
   that uniquely identifies the station. In an annual publication known as Callbook,
   the call signs were listed in this order: First by call district, then by suffix,
   then by prefix. When I created the Ham Domain database, I wrote a script to sort
   them in this order. First, I did it with CGI. Later, I did it with PHP. I could
   only accomplish it using a hidden value which I called the ‘sortcode’. It was
   never displayed. But it was instrumental in getting it in the right order. When
   an Amateur Radio Operator looks up a call, it is easiest if they are listed in
   this order. I am not a great programmer. But I can usually accomplish it if I
   give it the amount of time needed. That may be a good deal of time. I wrote a
   blurb explaining the dynamics of my sorting method. It was on my old Web site(
   before WordPress). I just republished it on the same URL as before. You can now
   read it at: [https://www.wb4aej.com/hamsort](https://www.wb4aej.com/hamsort) .
    -  This reply was modified 5 years, 2 months ago by [Fred Atkinson](https://wordpress.org/support/users/fatkinson/).
    -  This reply was modified 5 years, 2 months ago by [Fred Atkinson](https://wordpress.org/support/users/fatkinson/).
    -  This reply was modified 5 years, 2 months ago by [Fred Atkinson](https://wordpress.org/support/users/fatkinson/).
 *  Plugin Author [Yannick Lefebvre](https://wordpress.org/support/users/jackdewey/)
 * (@jackdewey)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/custom-table-6/#post-14108555)
 * Thanks for the link, but I am not sure if what you have now works you for or 
   if you’d still need to be able to get 15 random links and be able to sort them
   by custom text field #1? Or if what’s in place now is ok for you.
 *  Thread Starter [Fred Atkinson](https://wordpress.org/support/users/fatkinson/)
 * (@fatkinson)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/custom-table-6/#post-14108577)
 * It works, no problem.
    I would still like to sort them in this way if it is at
   all possible. But it works.
 *  Plugin Author [Yannick Lefebvre](https://wordpress.org/support/users/jackdewey/)
 * (@jackdewey)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/custom-table-6/#post-14111044)
 * As discussed via e-mail, I have added two new fields at the bottom of the Library
   Configurations Advanced tab to allow users to set a custom WP Query argument 
   and value for that argument. Once set, the following code in your theme’s functions.
   php file will sort the randomly selected items:
 *     ```
       // Filter to sort the random posts displayed
       add_filter( 'the_posts', function ( $posts, $q )
       {
           // First we need remove our filter
           remove_filter( current_filter(), __FUNCTION__ );
   
           // Check if our custom parameter is set and is true, if not, bail early
           if ( empty( $q->get( 'randomlinknamesort' ) ) ) {
               return $posts; 
           }             
   
           $top_10_items = array_splice( $posts, 0, intval( $q->get( 'randomlinknamesort' ) ) );
   
           foreach ( $top_10_items as $key => $item ) {
               $top_10_items[$key]->link_custom_text = get_post_meta( $item->ID, 'link_custom_text_1', true );
           }
   
           usort( $top_10_items, function ( $item1, $item2 ) {
               return $item1->link_custom_text <=> $item2->link_custom_text;
           });
   
           // Make sure we have a value for $major_array, if not, bail
           if ( empty( $top_10_items ) ) {
               return $posts;
           }        
   
           return array_values( $top_10_items );
       }, 10, 2 );
       ```
   
 *  Thread Starter [Fred Atkinson](https://wordpress.org/support/users/fatkinson/)
 * (@fatkinson)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/custom-table-6/#post-14111115)
 * Ok. I will have to remember to put that in the PHP file if I rebuild the site
   or if I change the theme.
    I have copied those lines into my iPad so I will have
   them if/when I need them. Thanks, Yannick.
 * Regards,
 *  Fred
 *  Thread Starter [Fred Atkinson](https://wordpress.org/support/users/fatkinson/)
 * (@fatkinson)
 * [5 years, 2 months ago](https://wordpress.org/support/topic/custom-table-6/#post-14136909)
 * Yannick,
 *  I am trying to find that ‘functions.php’ file in link-library.
 *  I checked every subdirectory but didn’t find it.
 *  I want to upgrade to the latest version of Link Library. But I don’t want to
   lose the sort routine when I do (I believe you said I would have to insert it
   each time the plugin was updated).
 *  Regards,
 *  Fred

Viewing 15 replies - 1 through 15 (of 26 total)

1 [2](https://wordpress.org/support/topic/custom-table-6/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/custom-table-6/page/2/?output_format=md)

The topic ‘Custom Table’ is closed to new replies.

 * ![](https://ps.w.org/link-library/assets/icon-256x256.jpg?rev=971117)
 * [Link Library](https://wordpress.org/plugins/link-library/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/link-library/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/link-library/)
 * [Active Topics](https://wordpress.org/support/plugin/link-library/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/link-library/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/link-library/reviews/)

## Tags

 * [links](https://wordpress.org/support/topic-tag/links/)
 * [sortcode](https://wordpress.org/support/topic-tag/sortcode/)
 * [table](https://wordpress.org/support/topic-tag/table/)

 * 26 replies
 * 2 participants
 * Last reply from: [Yannick Lefebvre](https://wordpress.org/support/users/jackdewey/)
 * Last activity: [5 years ago](https://wordpress.org/support/topic/custom-table-6/page/2/#post-14333128)
 * Status: resolved