sql for querying post and their category

To get a specific post in WordPress, you can use the get_post() function and get_the_category() to get the categories associated with it. You can then use the code found in this answer to dump the SQL queries used. <?php $post_ID = 7; $the_post = get_post( $post_ID ); $the_category = get_the_category( $post_ID );

why the current date do not update

From the codex: <?php $wpdb->update( $table, $data, $where, $format = null, $where_format = null ); ?> In your exampe ‘ CURDATE()’ is simply a string, not a MySQL function (or something else). The correct syntax for php’s date() is: date( [format], [timestamp] ) Try this: $this->wpdb->update( ‘wp_competitors’, array( ‘results’ => $tips, // json ‘update_time’ => … Read more

Display old posts if no future posts exist

example: <?php query_posts(‘posts_per_page=5&order=ASC&post_status=future’); if ( !have_posts() ) query_posts(‘posts_per_page=5&order=DESC&post_status=publish’); if( have_posts() ) : while ( have_posts() ) : the_post(); ?>

Custom Query Arguments

/** * Define a new function that uses $args and wp_parse_args() */ function explain_parse_args( $args ) { $defaults = array ( ‘text’ => ‘wp_parse_args() merges $args into $defaults’, ‘before’ => “”, ‘after’ => ” \n”, ‘echo’ => TRUE ); // Parse incomming $args into an array and merge it with $defaults $args = wp_parse_args( $args, … Read more

How to limit post query to only return a total count of items with certain post statuses?

WHERE post_status NOT IN (‘auto-draft’,’trash’) Looks like you can add that to your base query. /* — Preparing your query — */ $query = “SELECT * FROM $wpdb->posts WHERE post_status NOT IN (‘auto-draft’,’trash’) “; This is only barely a WordPress question. Why are you not using core functions for this? Also, NOT IN is not … Read more

Custom MySQL query to list post

You don’t need to use query_posts function. It could be done without it. Use setup_postdata function to set up global post data. $sql = ” SELECT p.* FROM orders_items oi INNER JOIN products pr ON pr.`post_id` = oi.`product_id` INNER JOIN posts p ON p.`ID` = pr.`post_id` AND p.`post_type` = ‘product’ GROUP BY oi.`product_id` ORDER BY … Read more

Make division in post_query?

MySQL can do math but can’t pass it through query_posts like that, or any WordPress’ post query functions, which depend upon WP_Query. They will literally look for a table/column named, in your case, “meta_value_num / date”. To do it in SQL I believe– aka., this is untested– you’d have to do something like this: SELECT … Read more

Add query string variables to all hyperlinks URL matching a specified domain

Sorry I read your question wrong. You probably want to use WP_Rewrite and do something like: add_filter( ‘rewrite_rules_array’,’my_insert_rewrite_rules’ ); add_filter( ‘query_vars’,’my_insert_query_vars’ ); add_action( ‘wp_loaded’,’my_flush_rules’ ); // flush_rules() if our rules are not yet included function my_flush_rules(){ $rules = get_option( ‘rewrite_rules’ ); if ( ! isset( $rules[‘(argument_1=test&argument_2=test2)$’] ) ) { global $wp_rewrite; $wp_rewrite->flush_rules(); } } // … Read more

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