How to create a widget like this?

Your question is a little short on detail, but let’s suppose you have retrieved the posts using wp_query and are looping through it like this: $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { $the_query->the_post(); STUFF } wp_reset_postdata(); } In the position of STUFF you want to distinguish … Read more

How to display a list of posts in same child category as current post

I just figured this one out by modifying the first foreach statement. $post_id = get_the_ID(); $cat_ids = array(); $categories = get_the_category(); if ( $categories && !is_wp_error( $categories ) ) { foreach( $categories as $category ) { if( 0 == $category->parent ) { continue; }else{ array_push( $cat_ids, $category->term_id ); } $current_post_type = get_post_type( $post_id ); $args … Read more

Using a Shortcode to List Posts from Multiple Categories

Maybe you can make it so that you can use the shortcode like [list-products categories=”1,2,3″], and then explode them as an array to insert them as your terms? <?php function list_products_func($atts) { $a = shortcode_atts(array( ‘categories’ => ”, ), $atts); // Check for multiple categories by comma if ( strpos( $a[‘categories’], ‘,’ ) !== false … Read more

Create one-use post dynamically, add to main query, do not insert post (user profile view)

From what I understand you are trying to change the permalink structure of the user, so instead of showing yoursite.com/author/yourusername it will show yoursite/profile/yourusername? You can add a rewrite rule to the permalink structure to make that change: function yourdomain_user_rewrite() { global $wp_rewrite; $wp_rewrite->author_base=”profile”; $wp_rewrite->author_structure=”https://wordpress.stackexchange.com/” . $wp_rewrite->author_base . ‘/%author%’; } add_action( ‘init’, ‘yourdomain_user_rewrite’ ); Then … Read more

Create a notification for post field

Basically what you would want is a daily task that sends those reminders, for that you would use WP Cron. I’m not gonna get into the logic of actually building the email (used your code). Here’s a basic setup: if ( ! wp_next_scheduled( ‘quote_reminder_hook’ ) ) { wp_schedule_event( time(), ‘daily’, ‘quote_reminder_hook’ ); } add_action( ‘quote_reminder_hook’, … Read more

How do I fit WP_Query arguments into a function?

This should work: $query->set( ‘date_query’, array( ‘relation’ => ‘OR’, array( ‘column’ => ‘post_date’, ‘after’ => ‘-7 days’ ), array( ‘column’ => ‘post_modified’, ‘after’ => ‘-7 days’ ) ) ); You might want to adjust the callback’s name, since it’s not only ordering the home page. You also have _asc in that name but are setting … Read more

Searching by title, content and custom taxonomy

[WP_Query][1] provides list of options including [Taxonomy Parameters][2]. You can use the taxonomy parameter to search the posts like: post_type’ => ‘firma’, ‘post_status’ => ‘publish’, ‘order’ => ‘DESC’, ‘orderby’ => ‘date’, ‘s’ =>$_POST[‘term’], ‘posts_per_page’ =>5 ‘tax_query’ => array( array( ‘taxonomy’ => $_POST[‘term’], ) );

Need help understanding this WP Query [closed]

You can try this code to show only post. if(isset($xt_corporate_lite_opt[‘xt_about_page’]) && $xt_corporate_lite_opt[‘xt_about_page’] != ”) { $args = array( ‘post_type’ => ‘post’); $xt_query = new WP_Query($args); if ($xt_query->have_posts()) { while ($xt_query->have_posts()) { $xt_query->the_post(); the_content(); } } wp_reset_postdata(); } if you have any doubt in WP_Query. then you could check this link in detail. https://codex.wordpress.org/Class_Reference/WP_Query

construct complex queries with WP User Query

$meta_query_args = array( ‘meta_query’ => array( ‘relation’ => ‘OR’, // Optional, defaults to “AND” array( ‘key’ => ‘_my_custom_key’, ‘value’ => ‘Value I am looking for’, ‘compare’ => ‘=’ ), array( ‘relation’ => ‘AND’, array( ‘key’ => ‘_my_custom_key_2’, ‘value’ => ‘Value I am looking for 2’, ‘compare’ => ‘=’ ), array( ‘key’ => ‘_my_custom_key_3’, ‘value’ => … Read more