Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to check wordpress custom table is empty or not [duplicate]

This question about wordpress cutom table.. I am creating a plugin I want to check a table named wp_school_post table empty or not.

See my code below which throws the following error

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\getwp\wp-content\plugins\getwp_P\schools_post_function.php on line 7

**filled** 

My code:

function schools_post_function()
{
//  echo "Sachool POST function";
    global $wpdb;
    $result = $wpdb->get_results("SELECT postid from wp_school_post WHERE `postid` IS NOT NULL");
    if(mysql_num_rows($result=='0'))
    {
        echo "not filled";
    }
    else
    {
        echo "filled";

    }
}
like image 996
Savan Paun Avatar asked Nov 26 '25 22:11

Savan Paun


1 Answers

Try this :)

<?php
function schools_post_function()
{
    global $wpdb;
    $result = $wpdb->get_results("SELECT postid from wp_school_post WHERE `postid` IS NOT NULL");
    if(count($result) == 0)
    {
        echo "not filled";
    }
    else
    {
        echo "filled";

    }
}
?>
like image 163
vivek Avatar answered Nov 29 '25 13:11

vivek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!