Converting an existing query_posts to WP_Query
Converting an existing query_posts to WP_Query
Converting an existing query_posts to WP_Query
Got some help from a friend and figured out that I needed to move the post_meta stuff into the query with meta_query then just set a fallback from there. <?php $current_date = date(‘Ymd’); $page_object = get_queried_object(); $page_id = get_queried_object_id(); // Match the string “123” to the database value a:1:{i:0;s:3:”123″;} (serialized array) for ACF $page_id = … Read more
If you use a Syntax highlighting editor, you may be able to spot these problems easier. Change this code: ‘category_name’ => “, To this code: ‘category_name’ => ”, That will fix the syntax error in your code.
You mention the Codex page for WP_Query but you are not using WP_Query. You are using wpdb. WP_Query is a very complicated class for querying the WordPress tables for post (CPT) data. wpdb is a lightweight wrapper around PHP SQL functions. With WP_Query you can pass arguments like monthnum because the WP_Query class converts the … Read more
Check out the WP_Query() function. You’ll be able to run multiple queries and get an array for each post type
… in the subcategories I am getting exactly the same results as in the parent category … That is what you told PHP to do. By the time the category.php file is processed, the $wp_query object contains a list of all posts that from the current category. This code throws that object away and replaces … Read more
var_dump your $args arguments: array(4) { [“cat”]=> string(7) “2,39,30” [“orderby”]=> string(14) “meta_value_num” [“order”]=> string(4) “DESC” [“meta_key”]=> string(12) “album_rating” } The second time you use a key, you overwrite the first time. You cannot build the array like that. The orderby parameter will take a space separated string, so this is closer: $args = array( ‘cat’ … Read more
You might try to add a posts_where filter in your pre_get_posts hook: function my_pre_get_posts( $q ){ if( $q->is_main_query() ) add_filter( ‘posts_where’, ‘my_posts_where’ ); return $q; } ! is_admin() && add_action( ‘pre_get_posts’, ‘my_pre_get_posts’ ); where function my_posts_where( $where ){ // your custom replacements on the $where string // … // remove the filter remove_filter( current_filter() , … Read more
Your code looks valid for me. The only thing you can try is ‘NUMERIC’ instead of ‘numeric’ and to cast $current to int as date() will return a string. $current = (int)date(‘Ymd’); To debug this further you can place this directly under your code: global $wpdb; var_dump( $wpdb->last_query ); You’ll then have the complete query … Read more
Update Post with Modified Data