ACF: How to make get_field() ignore the main wp query?

I resolved this by adding wp_query->is_main_query() to my clauses before I set the query update. Ie… // The filter code that shows only the current authors posts add_action(‘pre_get_posts’, ‘query_set_only_author’); function query_set_only_author( $wp_query ) { if( is_admin() && get_current_user_role()==”required_role” && $wp_query->is_main_query() ) { if ( basename($_SERVER[‘PHP_SELF’])==”edit.php”){ $wp_query->set( ‘author’, $current_user->ID ); } }

Remove the first 5 characters of the_title and orderby that

WordPress WP_Query’s orderby parameter has a lot of options but nothing as specific as what you are after. I think you’d have to do this after retrieving posts through the WP_Query, then sort them using usort(). Your code should be something like this. $args = array( ‘post_type’ => ‘z_day’, ‘posts_per_page’ => -1, ‘meta_query’ => array( … Read more

Assign category from custom field on post creation and update

After getting year, you may check if category exists using category_exists($cat_name); if not found then create category using wp_create_category( $cat_name, $parent ); after that you may create post using $my_post = array( ‘post_title’ => wp_strip_all_tags( $_POST[‘post_title’] ), ‘post_content’ => $_POST[‘post_content’], ‘post_status’ => ‘publish’, ‘post_author’ => 1, ‘post_category’ => array( 8,39 ) ); // Insert the … Read more

get all posts in custom post type by ACF field value

Meta Queries are nested arrays. See the WP_Query section on meta queries. Option 1 Use meta_key and meta_value directly in the query arguments, not as a meta query. $student_query_args = [ ‘post_type’ => ‘student_list’, ‘post_status’ => ‘publish’, ‘posts_per_page’ => 100, ‘order’ => ‘DESC’, ‘meta_key’ => ‘program_id’, ‘meta_value’ => 5317, ]; Option 2 The meta query … Read more

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