I designed a custom publish loop query according to data from another wordpress plugin.

I recieve this error:

Fatal error: Call to a member function have_posts() on a non-object

This is actually the code I've made:

You assign the choose to $most_viewed var, however you need to pass $sql variable. At first, change $most_viewed = to $sql = ...