Quantcast
Channel: Topic Tag: plugin | WordPress.org
Viewing all articles
Browse latest Browse all 26892

curtisbryant on "Some Query Results Listed Twice"

$
0
0

In my plugin, a page displays a dynamic list of post titles, authors, and other data in a table. The problem is that some posts are listed twice while the rest are listed once as intended. Some of the posts that are listed twice are published, and some are not. The posts represent college courses.

The course listed twice at the top of the list is listed only once in the wp_posts table, so duplicate data doesn't seem to be the cause. My guess is it's a logic error in the while loop below. Would you please take a look?

Here is the while loop that generates the table rows:

while ($row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC)) {
                                    var_dump( $row );
                                    $postTitle = $row['fkCourseSection'];

                                    $postType  = 'post';
                                    $postStatus= 'publish';
                                    $new_query = $wpdb->get_results( $wpdb->prepare(
                                        "
                                        SELECT *
                                        FROM wp_posts
                                        WHERE post_title = %s
                                        AND post_type = %s
                                        AND post_status = %s
                                        ",
                                        $postTitle,
                                        $postType,
                                        $postStatus
                                    ));

                                    if( count( $new_query ) > 0 ) {
                                        $authorinfo = get_userdata($new_query[0]->post_author);
                                    }

                                    if ( count($new_query) > 0 && ($new_query[0]->post_status === 'publish')) {
                                        echo "<tr><td style='text-align:center;'><i class='icon-ok'> </i></td>
                                        <td style='text-align:center;'><a href='../../themes/MCCSyllabusV1/MCCSyllabusV1/wkhtmltopdf/pdf.php/".str_replace('/', '', $new_query[0]->post_title)."><img src='../../themes/MCCSyllabusV1/MCCSyllabusV1/images/pdf.png' width='20px' border='0'></a></td>
                                        <td><a href='../../../".str_replace('/', '', $new_query[0]->post_title)."' target='_blank'>".$new_query[0]->post_title."</a></td>
                                        <td>".$row['FacultyName']."</td>
                                        <td>".$new_query[0]->post_modified."
                                        </tr>'";
                                    }
                                }

Viewing all articles
Browse latest Browse all 26892

Trending Articles