SQL Query to select post title & post ID from a particular category

You can use $args = array( ‘post_type’ => ‘post’ ,’posts_per_page’ => 10, ‘category_name’ => ‘orange’ ); $query = new WP_Query( $args ); printf( ‘<h2>Generated SQL:</h2><pre>%s</pre>’, $query->request ); to display the generated SQL query. The above example will give you: <h2>Generated SQL:</h2> <pre> SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE … Read more

Remove last comma from this query

Looks like you’re trying to build up some JSON. Why not use what PHP already provides, which has the advantage of escaping characters too? global $post; $data = array(); if ($loop->have_posts()) { while ($loop->have_posts()) { $loop->the_post(); $thumb=wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), ‘full’); $thumb2=wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), ‘medium’); $url = rwmb_meta( ‘smb_katalozi’ ); $data[] = array ( ‘image’ => … Read more