use mysql variable in a $wpdb->query to reindex a column?

If I correctly understood, this is not possible (two queries instead of one). I ended up with this sad and time-consuming loop… :/ //get subtracks $querystr = $wpdb->prepare(“SELECT subtrack_id FROM `$subtracks_table` WHERE tracklist_id=’%d’ ORDER BY `subtrack_time` ASC”,$this->post_id); if ( !$ids = $wpdb->get_col($querystr) ) return; //update order $i = 0; foreach($ids as $id){ $i++; $wpdb->update( $subtracks_table, … Read more

How do I insert a custom post type query after a certain number of recent posts and then resume recent posts?

I’d make a loop with 12 posts per page and after printing 4 posts I’d call another loop with 6 custom posts. Then go back and print the last 8 posts of current page. <?php $index = 1; $paged = ( get_query_var(‘paged’) ) ? get_query_var(‘paged’) : 1; $posts = new WP_Query(array(‘post_type’ => ‘post’, ‘posts_per_page’ => … Read more

How can I fetch all the dates from custom fields from various different custom post types and show / list them at one place in ascending order?

get_post() and get_post_meta() should work to collect the data and array_multisort() should be able to sort it into ascending order. // Query the database to get the posts from your post types $project_args = array( ‘post_type’ => ‘projects’, “numberposts” => -1 ); $task_args = array( ‘post_type’ => ‘tasks’, “numberposts” => -1 ); $material_args = array( … Read more

WordPress – Form does not filter the results of taxonomies

Try below code for search using date and category. $_name = $_GET[‘date-picker-example’]; $categoria = $_GET[‘categoria_evento’]; $today = date(‘Ymd’); // Start the Query $v_args = array( ‘post_type’ => array(‘eventi-suite’), // your CPT ‘posts_per_page’ => -1, ‘meta_value’ => $_name, // looks into everything with the keyword from your ‘name field’ ‘order’ => ‘ASC’, ‘orderby’ => ‘metakey_AMC_data’, ‘meta_query’ … Read more

Count post meta entries

WP_Query has a property that returns the no of posts that match your query. You can print it as follow in your first try: $query = new WP_Query( $args ); echo $query->post_count;

Add code to the header of posts by particular author

is_author() is not for determining current user, it checks whether the Author archive page is in display or not. Your call would be to use wp_get_current_user() or get_current_user_id() (if you are comfortable with user ID) or any similar function WP have. Example of using wp_get_current_user() <?php $current_user = wp_get_current_user(); if ( ‘ritesh’ === $current_user->user_login ) … Read more