Simple question…
wanna create something like this:
$args = array(
'post_type' => 'posts',
'limit' => 5,
'cat' => 'news'
);
Then, a function that can actually get these ‘keys’… like:
function get_posts($args) {
$post_type = $args['post_type'];
$limit = $args['limit'];
$cat = $args['cat'];
$sql = mysql_query("SELECT * FROM posts WHERE posttype='$post_type' .... ");
// other code...
}
how can i?
Sorry for bad english and thanks in advance.
Please, don’t use
mysql_*functions in new code. They are no longer maintained and the deprecation process has begun on it. See the red box? Learn about prepared statements instead, and use PDO, or MySQLi – this article will help you decide which. If you choose PDO, here is a good tutorial.However, it seems that you have already answered yourself!
You should call the function this way:
If you get some errors, please update your question with error log.