24

I need to make a query in a WordPress plugin but I couldn't find a WordPress function and I'm not sure is right to use mysql_query

The functions I've found enable ordering and grouping but I need to use also join and in (list).

Is there a way?

2 Answers 2

24

It looks like you'd want to use the $wpdb class (which has functions for directly accessing and manipulating the wordpress database). It lets you do things like:

<?php $wpdb->query('select * from my_plugin_table where foo = "bar"'); ?>

Documentation here.

Sign up to request clarification or add additional context in comments.

1 Comment

Note to anyone looking at this answer as it comes up on the first page of Google results, it will just return the number of rows affected for this and some other queries and in other cases it will return true. If you want to get data then use $wpdb->get_results
18

To pull out rows maybe you'd use:

$myrows = $wpdb->get_results( "SELECT id, name FROM mytable" );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.