Get all posts which was posted on X Days WordPress

You can try following code $y = date(‘Y’); $m = date(‘m’); $d = date(‘d’,strtotime(“-7 days”)); //Date you want $args = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘post’, ‘date_query’ => array( array( ‘year’ => $y, ‘month’ => $m, ‘day’ => $d, ), ), ); $posts= new WP_Query( $args ); //you will get posts which are posted … Read more

wp_query get data from advanced custom field in wordpress

ACF plugin stores data in the wp_postmeta like the default WordPress custom fields. To get data from a custom field your code should look like this (assuming the custom field name is “brand_name”). $title = get_the_title(); $the_query = new WP_Query( array( ‘posts_per_page’=>9, ‘post_type’=>’product_name’, ‘order’ => ‘ASC’, ‘meta_query’ => array( array( “key” => “brand_name”, “value” => … Read more

Is it possible to query from external database? [duplicate]

You can use wpdb to setup a new connection. Add something similar to this below in your functions.php and you can then query just like you would normally but using the new connection. $second_db = new wpdb(DB_USER, DB_PASSWORD, $database_name, DB_HOST); $results = $second_db->get_results($your_query); references: https://wordpress.stackexchange.com/a/1673/86845 https://stackoverflow.com/a/36759606/3204142

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

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