wp query - How get attachment id from its title in Wordpress? -
this not work:
$args = array( "post_per_page" => 1, "post_type" => "attachment", "post_title" => trim( "my attachment" ) ); //this empty $get_posts = new wp_query( $args ); i know attachment exists post title because searching id returns object post_title = "my attachment".
how can find attachment post title?
sorry delay ... can use direct query class wpdb..
global $wpdb; $str= "my attachment"; $posts = $wpdb->get_results( "select * $wpdb->posts post_title = '$str' ", object ); if ( $posts ){ foreach ( $posts $post ){ echo $post->post_title; } } but beware! protects code sql injection attacks read more in http://codex.wordpress.org/class_reference/wpdb#protect_queries_against_sql_injection_attacks
Comments
Post a Comment