Tag Info

Hot answers tagged

3

You can do this with pre_get_posts. This hook is called after the query variable object is created, but before the actual query is run. For excluding category id 32 and 39 from homepage, you can setup a function like this. function wpse_exclude_categories( $query ) { if ( is_admin() ) return; if ( $query->is_home() && ...


2

You can try using wp_insert_post_data for the task. Something like: function assign_new_post_to_specific_author( $data , $postarr ) { // Where author_ID is the ID of the author you want to assign the new post $data['post_author'] = author_ID; return $data; } add_filter( 'wp_insert_post_data', 'assign_new_post_to_specific_author', '99', 2 ); ...


2

<?php $args = array( 'posts_per_page' => -1, 'post_type' => 'event', 'meta_query' => array( array( 'key' => 'event_date_end_timestamp', 'value' => time(), 'type' => 'numeric', 'compare' => '<' ) ) ); $programs = new WP_Query($args); ?> ...


1

Wrong hook, because what gets passed to wp is the Current WordPress environment instance not The WP_Query instance like it is e.g. passed to loop_start. You could actually just do your check inside the function callback you hook to loop_start. Edit/note: You could just have done global $wp_query; inside the wp hook, it is actually the ...


1

First of all, never use query_posts, use WP_Query to create additional queries. You can target specific post positions in the loop by using the built in current_post var of the query object. Here's an example using the post_class function: <?php $my_posts = new WP_Query( array( 'posts_per_page' => 3 ) ); if( $my_posts->have_posts() ): while( ...


1

Technically speaking, Woocommerce products are just another WordPress post object with a customized post type (which is product in this case). If you take a look at the create_product function inside class-wc-api-products.php, you'll see this line: // Attempts to create the new product $id = wp_insert_post( $new_product, true ); So the API ends up using ...


1

You are almost there. You just need to use wp_mail to send emails containing in your array. Here is how you can achieve that using save_post action hook. /** * To send email on updating your event post * * @param int $post_id The post ID. * @param post $post The post object. * @param bool $update Whether this is an existing post being updated or not. ...


1

You have one or two issues here and possible future bugs that you might encounter term in your tax_query should be terms Be carefull with terms having dates as names and especially dates as slugs. This can cause issues and unexpected results if custom permalinks clash or if something falls into the template hierarchy for some reason. Never use the name ...


1

Just run a normal tax_query and set the field parameter to slug in the query. I assume that you already have a way getting the array of slugs (Requires PHP5.4+) $args = [ 'post_type' => 'product', 'posts_per_page' => 12, 'tax_query' => [ [ 'taxonomy' => 'TAXONOMY_NAME', 'field' => ...


1

In most of case, it would bee easier to use a Custom Post Type instead of creating a new table then it can solve you encoding problem because WordPress use unicode


1

You can use publish_post action hook for notifying post author. function wpcs_author_notification( $post_id ) { $post = get_post( $post_id ); $author = get_userdata( $post->post_author ); $message = "Hi " . $author->display_name . ", Your post, " . $post->post_title . " has just been published at " . get_permalink( $post_id ); ...


1

I think that by adding a delay you're not really fixing the issue, you're simply hiding it, until you grow and add more media and servers, so lsyncd will take longer, and you'll have to increase your delay every time. Also what about updating existing posts? People might add media items and update, or add more items to a gallery, you'll have to add delays ...


1

try this $post_id = 11; $post = get_post($post_id); $slug = $post->post_name; <a href="<?php get_site_url(); ?>/abstract/<?php echo $slug; ?>" title="<?php the_title_attribute(); ?>">Abstract</a>


1

Don't forget that when you are adding a filter it will stay there for all subsequent request. I would suggest you remove the closure and do something like this: function x_example( $input ) { remove_filter( 'posts_where', 'x_example' ); return $input; } add_filter( 'posts_where', 'x_example' ); You will have to do the same thing for the posts_join ...


1

There is nothing build-in to create the drop-down for you, so you have to do it yourself. To get the needed information you can use get_post_types() to get the post types you want, set the $args parameter accordingly. Additionally make sure to set the $ouput parameter to objects, because you need the data provided - it defaults to names and then you will ...


1

Create a template with a WP_Query to get posts with post type "post" then create a page and assign that template to that page. Templates: https://codex.wordpress.org/Templates Query by post type: https://codex.wordpress.org/Class_Reference/WP_Query#Type_Parameters


1

Exist some WordPress function that retrieve the list of links (in my specific case only one) that are into a post? Check out the core wp_extract_urls() function: $urls = wp_extract_urls( $content ); that will extract urls from any given content. Example $content = 'Two test sites: <a href="http://foo.tld">Foo.tld</a> and ...


1

As you have stated, rank is defined by a value in a custom field, so you would just need to get the value from the custom field and display it. You can try the following inside your loop global $post; // Just make sure the custom field name is correct $rank = get_post_meta( $post->ID, 'custom_field', true ); // Display the title and rank echo 'Rank ' ...


1

do_shortcode([espro-slider id=21]) will process the shortcode and return the result. The Codex describes exactly this example: // Use shortcode in a PHP file (outside the post editor). echo do_shortcode( '[gallery]' ); You can often just call the callback directly also: function generic_shortcode_callback($atts,$content) { return "Yay! ".$content; } ...



Only top voted, non community-wiki answers of a minimum length are eligible