WordPress SQL – How to Check for Category?

And I want to add an additional condition that the post be in a specific category. Any thoughts? JOINing on the taxonomy tables is complicated. Unless you have a good reason why you have to use SQL, don’t. Use WP_Query. $args = array( ‘post_type’ => $holder, ‘numberposts’ => -1, ‘post_status’ => array(‘publish’), ‘category_name’ => ‘cat-slug’, … Read more

When sorting WP_List_Table, table sorts, but I also get SQL errors

the part ORDER BY $orderby $order LIMIT get translated to ORDER BY asc LIMIT, the columnname that supose to be in $orderby is missing, and there for the sql fail. looks like you want your default value to be ‘title’ $orderby = (isset($_REQUEST[‘orderby’]) && in_array($_REQUEST[‘orderby’], array_keys($this->get_sortable_columns()))) ? $_REQUEST[‘orderby’] : ‘title’; may geuss is that in_array() … Read more

Select column name dynamically mySQL Query

I guess one could argue that this is somewhat wordpress related, because you are trying to get_results() from $wpdb, but like @MarkKaplun said your problem is that you are using the SQL wrong. Below code is an example on how to do it correct: $dr = $wpdb->get_results( $wpdb->prepare( “SELECT * FROM wp_shipping WHERE country = … Read more

Help me SELECT thumbnail from SQL and use

You do not need to be messing with the database connection. WordPress provide a database object called $wpdb. It is not really clear what you are doing. Your title reads “help me select thumb”, but your code is actually pulling a lot of different post statuses, not thumbnails. In fact, your code does not have … Read more

How to display data from db in select list [closed]

You’re recreating the select element on every iteration through the loop, and you need to name your current loop assignment variable differently, as you’re overwriting your original. Lastly, you’re also not assigning a value to the options within the loop, so you’re not going to get anything on the form submission, and text isn’t a … Read more

Randomly select one of last 3 posts

$args=array( ‘orderby’ => ‘rand’, ‘order’ => ‘DESC’, ‘posts_per_page’ => 3, ‘offset’ => $offset, ); $q = new WP_Query($args); if($q->post_count>0){ $random_post = $q->posts[mt_rand(0,2)]; } also, just a little note, ORDER BY RAND() is pretty bad for performance

How to SQL query posts IDs by categories AND authors?

Not the best solution 😛 but this could help you: select distinct(p.ID) from wp_posts p, wp_term_relationships r, wp_term_taxonomy tt, wp_terms t WHERE p.post_author in (1, 2, 3) and r.object_id = p.ID and tt.term_taxonomy_id = r.term_taxonomy_id and tt.taxonomy = ‘category’ and tt.term_id = t.term_id and t.term_id in (1, 2, 3);

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)