I have created a small plugin with a shortcode that displays the siblings of the person whose page the shortcode is used on. The shortcode works fine and I can display everyone who share the same parents (see http://lyons-barton.com/sidney-george-robson-8/). As you can see Sidney Robson appears in the list. I wish to ignore/hide that as it is his page. My query is how do I ignore or leave out the person whose page the shortcode is on. Ie I want a list of the brothers and sisters. The code I used to create the shortcode and display this list is: <?php // Create Menu shortcode function add_a_sibling( $atts ) { extract( shortcode_atts( array( 'id' => '', ), $atts ) ); ob_start(); // Obtain the information for the list include ('tablename.php'); // This contains the the table name $result = $wpdb->get_results( "SELECT * FROM $table_name WHERE id = '$id'" ); $father_id = $wpdb->get_var( "SELECT father_id FROM $table_name WHERE id = '$id'" ); $mother_id = $wpdb->get_var( "SELECT mother_id FROM $table_name WHERE id = '$id'" ); $sibling = $wpdb->get_results( "SELECT * FROM $table_name WHERE father_id = '$father_id' OR mother_id = '$mother_id'" ); ?> <!-- Create the table to display the list --> <span class="table_heading">Siblings</span> <table class="menu_table"> <th class="menu_heading"> ID </th> <th class="menu_heading"> First Name </th> <th class="menu_heading"> Family Name </th> <th class="menu_heading"> View Page </th> <tr> <?php // Loop through the results to display the obtained information foreach ($sibling as $sibling){ $sibling_id = $sibling->id; ?> <tr class="menu_list"> <td ><?php echo $sibling_id;?></td> <td ><?php echo $sibling->first_name;?></td> <td><?php echo $sibling->family_name;?></td> <td><a href="<?php bloginfo('url'); ?>?p=<? echo $sibling->post_id ?>" target="blank">View Post</a></td> </tr> <?php } ?> </tr> </table> <?php $output = ob_get_clean(); return $output; } add_shortcode( 'siblings', 'add_a_sibling' ); Any assistance or guidance is appreciated Regards Warwick
Finally found the solution: changed the $sibling = $wpdb->get_results( "SELECT * FROM $table_name WHERE father_id = '$father_id' OR mother_id = '$mother_id'" ); to $sibling = $wpdb->get_results( "SELECT * FROM $table_name WHERE (mother_id = '$mother_id' OR father_id = '$father_id') AND id <> '$id'" );
Some advice -- you might want to learn more about the tags and attributes that go into tables and STOP throwing classes at everything for no good reason. THEAD, TBODY, CAPTION, SCOPE... It's also generally easier to NOT open and close PHP willy-nilly like that... and you probably shouldn't be building query strings that way since that probably means whatever the devil that object you are calling is, it's still using those mysql_ functions that we've been told for almost a decade to stop using, and they finally put big red warning boxes on php.net for the same reasons... you're also opening and closing one more TR than should be there, and of course you've got the target attribute which has no business being used on any website written after 1997. (unless of course your doctype is a FRAMESET) echo ' <span class="table_heading">Siblings</span> <table class="menu_table"> <caption>Siblings</caption> <thead> <tr> <th scope="col">ID</th> <th scope="col">First Name</th> <th scope="col">Family Name</th> <th scope="col">View Page</th> </tr> </thead><tbody>'; foreach ($sibling as $sibling) { $sibling_id = $sibling->id; echo ' <tr> <th scope="row">',$sibling_id,'</th> <td>',$sibling->first_name,'</td> <td>',$sibling->family_name,'</td> <td> <a href="',bloginfo('url'),'?p=',$sibling->post_id,'"> View Post </a> </td> </tr>'; } echo ' </tbody> </table>'; Code (markup): Much cleaner, and has all the hooks it needs to apply styling without all those extra pointless classes in the markup.