How to display a number of posts based on a Advanced Custom Field (ACF)

Found an answer to my question using the ACF plugin get_field function (http://www.advancedcustomfields.com/resources/functions/get_field/) to retrieve the value of the custom field, save it as a variable and then use it as part of the query_post parameters: <!– Modify query object –> <?php $num_news = get_field(“number_news”, 523); // number of news items to feature query_posts(‘showposts=”.$num_news.”&post_type=news’); ?> … Read more

WP MS: How to query over the network

[*] Each site in a Multisite network is considered to be exactly that — a separate site. All the $wpdb values (eg, $wpdb->posts) are distinct for each site. You can use switch_to_blog() and restore_current_blog() to get content (posts, etc) from the various sites[*] in your network: $sites = array( 1, 2, 3, ); $all_posts = … Read more

How to echo the_title from an array of posts?

try to use get_posts instead , as I read in http://codex.wordpress.org/Function_Reference/query_posts you can use this code: global $post; $args = array(‘posts_per_page’ =>3,’category’ => 3 ); $myposts = get_posts( $args ); foreach( $myposts as $post ) : setup_postdata($post); the_title() endforeach; wp_reset_postdata(); Regard’s.

Remove Post if Advanced Custom Field is checked to fix paging

Use WP_Query instead, and you can use the meta_key / meta_value parameters: <?php $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $args = array( ‘cat’ => 10, ‘paged’ => $paged, ‘posts_per_page’ => 12, ‘post_status’ => ‘any’, ‘order’ => ‘ASC’, ‘meta_key’ => ‘archived’, ‘meta_value’ => ‘true’ ); $posts = new WP_Query($args); ?> <?php while($posts->have_posts()): $posts->the_post(); ?> <?php … Read more

Display specific posts on home page

You have to know the ID/s of the category/categories you wish to show. Then add ‘category’ => ‘X’ in the array. X is the ID of your category. Example: $args = array( ‘numberposts’ => ‘5’, ‘category’ => ‘3’ ); or if you wish more then one category: $args = array( ‘numberposts’ => ‘5’, ‘category’ => … Read more

WordPress query portfolio posts

You can simply just add the cat or category_name parameter to your query. When using cat, you should use the category ID, and should you use category_name, it should be the slug of the category, not the name. Change <?php $tarali_query = new WP_Query(‘posts_per_page=”.$nbmax.”&ignore_sticky_posts=1&paged=’.$paged); ?> to <?php $tarali_query = new WP_Query(‘posts_per_page=”.$nbmax.”&cat=CATID&ignore_sticky_posts=1&paged=’.$paged); ?> For futher reading: … Read more

Max Posts and Memory Limit

For me, this was happening b/c of post meta cache issues. This article suggested code which solved my issue – and apparently many other’s as well. https://junaid.dev/wordpress-admin-fix-fatal-error-allowed-memory-size-error/?unapproved=369&moderation-hash=bd9064ea40d413150d8a42599c13f4f5#comment-369 Here is the code he provides: function jb_pre_get_posts( WP_Query $wp_query ) { if ( in_array( $wp_query->get( ‘post_type’ ), array( ‘my_post_type_1’, ‘my_post_type_2’ ) ) ) { $wp_query->set( ‘update_post_meta_cache’, false … Read more

query_posts orderby multiple ways

First you need to use the WP_Query to get those posts. Then you can orderby using the following array. // The Query $args = array( ‘cat’ => $category->term_id, ‘posts_per_page’ => -1, ‘orderby’ => ‘meta_value’, ‘meta_key’ => ‘_bunyad_review_overall’, ‘paged’ => ( get_query_var(‘paged’) ? get_query_var(‘paged’) : 1 ), ); $the_query = new WP_Query( $args ); // Create … Read more

posts_nav_link pulling in multiple post types

query_posts should be avoided at all costs. This is not just my emphasis, but the codex’s as well Note: This function isn’t meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query … Read more

Exclude a category of posts in author template

Never use query_posts, use pre_get_posts to modify any main query. function wpd_exclude_author_category( $query ) { if ( $query->is_author() && $query->is_main_query() ) { $query->set( ‘category__not_in’, array( 42 ) ); } } add_action( ‘pre_get_posts’, ‘wpd_exclude_author_category’ );

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