0

I want to show a list generated from two tables. I have a page with a shortcode that loads the information just like I want. The shortcode runs a function called member_list. In this function, I have a form with a POST in it that runs the same function when the form is submitted. I check to see which action is calling the function and add <?php get_header(); ?> and <?php get_footer(); when run from the POST. My problem is that the POST's resulting page looses it's formatting and throws four of these messages

Notice: Trying to get property of non-object in D:\www.foo.com\wp-includes\admin-bar.php on line 6. 

What am I not doing. This is my function.

function member_directory($sort_order, $first_time) {
    global $wpdb;
    if (!$first_time){
        get_header();
    }

    if ($sort_order == 1) {
        $where_clause = "LotNoSorting";
    } elseif ($sort_order == 2) {
        $where_clause = "last_name, first_name";
    } elseif ($sort_order == 3) {
        $where_clause = "recordedsubdivision, block, lotnum";
    } elseif($sort_order == 4){
        $where_clause = "street, housenum";
    } else {
        die ("Internal Error 1");
    }
    $sql =  "SELECT subscr_id, first_name, last_name, block, housenum, lotnum, lotno, lotnosorting, recordedsubdivision, street FROM wp_swpm_members_tbl LEFT OUTER JOIN plcoa_lots ON wp_swpm_members_tbl.subscr_id = plcoa_lots.lotno WHERE block <> '' ORDER BY " . $where_clause ;
    $query = $wpdb->get_results($sql);
    if (!empty ($query) ) {
    ?>
    <table>
        <form method="post" action="http://priestlakecoa.org/wp-admin/admin-post.php">
            <td > 
                <input type="submit"  value="Lot #" name="lot">
                <input type="hidden" name="action" value="member_directory">
            </td>
            <td >           
                <input type="submit" value="Name" name="name">
                <input type="hidden" name="action" value="member_directory">
            </td>       
            <td >
                <input type="submit"  value="Subdivision - Blk / Lot" name="subdivision">
                <input type="hidden" name="action" value="member_directory">
            </td>        
            <td >
            <input type="submit" value="Address" name="address">
                <input type="hidden" name="action" value="member_directory">
            </td>       
        </form>

        <?php
            foreach ($query as $row) {
        ?>
        <tr>
            <td><?php echo $row->subscr_id; ?></td>
            <td><?php echo $row->first_name . " " . $row->last_name; ?></td>
            <td><?php echo $row->recordedsubdivision . " " . $row->block . "/" .$row->lotnum; ?></td>
            <td><?php echo $row->housenum . " " . $row->street ; ?></td>
        </tr> 
        <?php
            }
            if (!$first_time){
                get_footer();
            }
        ?>
    </table>
        <?php

        } else {

            echo "Nothing found";
        }
}
  • Just had a thought. Should I be using 4 pages each with a different parameter passed to the shortcode specifying with format to use? That seems easy - if I can load a page from code. – Bud Apr 19 '18 at 0:26
0

I added 3 more pages to my site, one for each sequences that I wanted in the report. Then added a parameter to the shortcode in each page specifying the desired sequence and modified the function handling the shortcode to pass the parameter to the function building the report. Then just redirected to the page I wanted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.