Best choice for multiple loop in page?

get_posts() is just a wrapper for WP_Query, however it does have two main differences: get_posts() just returns an array of posts, so doesn’t provide methods for a Loop. get_posts() sets the ignore_sticky_posts and no_found_rows arguments to true. no_found_rows is required for pagination, and disabling it improves performance. #1 means means that you need to use … Read more

Custom WP_Query id

This is a very unusual way of accomplishing what you wanted but my problem is that the query filter receives via get the ID, With that suppose I have two posts one with the id=10 and another with the id=100 ends up that only the post from id 10 is listed. I do not know … Read more

Config.php issue in WordPress

Look for FS_CHMOD_DIR in wp-config.php. You can only define constants once. If it’s defined multiple times, you will get a PHP notice. Notices aren’t often a cause for concern, but they can reveal places you may have issues across the site. You can disable these from displaying to your visitors by defining WP_DEBUG as false.

insert value from html into data base with wordpress

If you want to insert content into the posts table, you should create a new custom post type first. Once you have a custom post type, you can follow through with what you’re doing above with a couple changes. <?php function insert_post() { // Check to make sure your content exists. if ( ! isset( … Read more

Exclude posts with specific metadata from search?

You need an additional parameter meta_query in the WP_Query arguments. $query_args = [ ‘posts_per_page’ => -1, ‘s’ => esc_attr( $_POST[‘keyword’] ), ‘post_type’ => ‘visitor’, ‘meta_query’ => [ ‘key’ => ‘visitor-hide’, ‘value’ => ‘yes’, ‘compare’ => ‘!=’, ] ] or in cases like yours (query by single custom field): $query_args = [ ‘posts_per_page’ => -1, ‘s’ … Read more

Woocommerce – exclude only older out-of-stock items

Most information necessary can be found at the Code Reference: WP_Query | Class . Otherwise useful resource Theme Handbook: Conditional Tags. Below code contains some clarifying comments. Please note, this is untested code, so no guarantees, but it should get you going. add_action( ‘woocommerce_product_query’, ‘custom_woocommerce_product_query’ ); function custom_woocommerce_product_query( $q ) { if ( ! is_admin() … Read more

WordPress wp_query() basic question about args

Your 3rd option is correct. $args3 = array( ‘posts_per_page’ => 9, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, // If you’re only specifying one. Use array( ‘projects’, ‘post’ ); for many. ‘post_type’ => ‘projects’, // This is the correct syntax for a taxonomy query. ‘tax_query’ => array( array( ‘taxonomy’ => ‘projects_categories’, ‘terms’ => $cat_id, ), ), … Read more

infinite loop in wp_query using simple query

I’m not certain why it would cause an infinite loop, but make sure not to use $wp_query as the variable name for your custom query. It’s a reserved global variable for the main query. Use a different name for the variable. I’d also suggest using wp_reset_postdata() after the loop: $my_query = new WP_Query( $args ); … Read more