add_action( "save_post_{CPT}", 'update_sticky', 15, 1 ); function update_sticky( $post_id ) { $stickies = get_option( 'sticky_posts' ); if ( ! in_array( $post_id, $stickies ) ) { $stickies[] = $post_id; update_option( 'test', $stickies); update_option( 'sticky_posts', $stickies ); } } It does work for test option I created for testing, but it doesn't work for existing sticky_posts option, although everything is the same. It does work for both if I hardcode the $post_id, like: $stickies[] = 123; Tried it in functions.php file, as …
The problem WordPress supports the sticky option with some of its default post types and doesn't provide any option to extend this to other post types. It's hard-coded in the met-boxes.php file: <?php if ( 'post' === $post_type && current_user_can( 'edit_others_posts' ) ) : ?> <span id="sticky-span"><input id="sticky" name="sticky" type="checkbox" value="sticky" <?php checked( is_sticky( $post_id ) ); ?> /> <label for="sticky" class="selectit"><?php _e( 'Stick this post to the front page' ); ?></label><br /></span> <?php endif; ?> Available solutions I googled …
How do you get sticky posts to work with categories? I have tried: $query->set( 'ignore_sticky_posts', 0 ); but this just results in an out of memory error. I have tried restricting posts on the blog page by category, but sticky posts are shown regardless of which category they are in. Why is this basic functionality so hard to achieve? Is the only option to write two separate custom queries?
What I'm able to do : When there is a sticky post in the current category, I'm already able to display it. The problem occurs when there is no sticky post : it doesn't display the latest post as it should do (actually id doesn't display anything). It works like a charm on the Home page : when there is a sticky post, it displays it, and where there is no sticky post, it displays the latest post. Here is …
Background: The Wordpress Answers site has two questions which ask about how to enable sticky posts on custom post types (see how to make custom posts sticky? and Enable sticky posts to custom post_type ). Both questions made mention of this trac ticket ( https://core.trac.wordpress.org/ticket/12702 ). The answers provided ( to those questions I mentioned above ) express a possibility of using custom post types and meta-boxes. Unfortunately the level of detail in those answers was not helpful to me …
I'm using my index.php to display post archive pages rather than a specific archive.php file. This works fine, however sticky posts do not stick to the top of it. They do however, stick to the top of the posts page. Are sticky posts not supposed to stick to the top of archive pages? Here is the code for the loop I'm using; loop-index.php - http://pastebin.com/NHi2tsNM Am I doing something wrong? Or is this just default functionality?
I am trying to modify the number of posts_per_page in the loop. This way: function posts_per_page($query) { $query->query_vars['posts_per_page'] = 3; } add_filter('pre_get_posts', 'posts_per_page', 11); The problem I have is that when I do so, then sticky posts appear twice in the loop: first one at the begining of the loop and second one in their original position. So in this case, the first page has 4 posts (3 of loop without sticky + the sticky post), and the sticky post …
Question What would be the best way to pin certain posts to the beginning of a custom loop that queries for many custom post types and may or may not have tax queries inside? Due to how the rest of the theme works, I would prefer if it could be handled in a single query (The process may use more than one query but at the end I'd prefer to have one final query that can be looped through). SQL …
so i have a blog and i want to make a post a sticky post that stays at the top. But for some reason, on the home page where i only display 4 posts, the sticky post doesn't work when the sticky post isn't in the newest 4 posts. It all works perfectly in the "All Posts Page" though. Anybody know how to fix this issue? thanks
The Setup I have divided my blog into 3 categories with their respective slugs. There are 3 pages corresponding to these 3 categories with their respective custom page templates. On each page, I want to loop through just the posts that correspond to that category. So let's say I have a page for the "videos" category: $videoPosts = new WP_Query( array( 'posts_per_page' => get_option( 'posts_per_page' ), 'category_name' => 'videos')); Then I stuck that into the loop just below: if ( …
Is there a way to feature one single custom post per day on the homepage, cycling through each of about twenty posts alphabetically and then starting over again from the first post? I'm thinking the answer found here to a similar question might be the direction I need to go, but I'm not entirely certain: https://wordpress.stackexchange.com/a/325554/199183 This is the custom functioned I borrowed from the above answer: add_action( 'wp', function () { if (! wp_next_scheduled ( 'mark_posts_as_featured_event' )) { wp_schedule_event(time(), …
I'm trying to exclude 3 Sticky posts from my blogs loop, I tried some snippets of code, but with no success. I could use some help. <?php if ( $posts->have_posts() ) : ?> <?php /* Start the Loop */ ?> <?php while ( $posts->have_posts() ) : $posts->the_post(); ?> <?php get_template_part( 'content', get_post_format() ); ?> <?php endwhile; ?> <div class="clearfix"></div> <?php else : ?> <?php get_template_part( 'content', 'none' ); ?> <?php endif; ?> <div class="clearfix"></div> <?php $wp_query = new WP_Query($args); global …
I have a permanent sticky post on my front page and have implemented the code (pasted below) into my functions.php file to stop it adding an extra post to my post count on the front page (it's a grid so i can't have one post dangling off the bottom). However.... when the code is implemented it's adding a whopping 72 extra pages to my page count. From 799 (which is what it should be) to 871. Any page past 799 …
I'm using pre_get_posts to adjust the number of posts displayed on my homepage. function lifelounge_query_adjust( $query ) { if ( is_home() ) { set_query_var( 'posts_per_page', 12 ); return; } } add_filter( 'pre_get_posts', 'lifelounge_query_adjust' ); But I am running into a problem with sticky posts. Basically, if I have any sticky posts, the query will display more than the 12 posts I have specified, because it will display 12 plus any sticky posts. I could, of course, ignore sticky posts: function …
So, I have the following code written inside my function.php. I use it on my blog post to display the sticky post, but my only issue is I'm not sure how to get the permalink inside my HTML. Also, how can I assign a post as sticky, but only show it in my shortcode? Right now this shortcode displays above all my posts, but then the sticky post is posted again at the top (I understand this is the correct …
We all know that ignore_sticky_posts is used to exclude sticky post from your custom query. But why on codex page https://codex.wordpress.org/Sticky_Posts, they use ignore_sticky_posts in querying sticky posts?? $args = array( 'posts_per_page' => 1, 'post__in' => get_option( 'sticky_posts' ), 'ignore_sticky_posts' => 1 ); $query = new WP_Query( $args ); This is so confusing and doesn't make any sense, you want it and yet you exclude it?
I would like to "highlight" a featured post above all other posts with a special indicator. Is there a feature in WordPress that will do this or do I need to install a third party plug-in? I am using a custom WordPress install (not WP hosted).
i've two questions. I would like to move Woocommerce-tabs underneath my short description on the right side. I found this but the accordion is not full-width. remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_product_data_tabs', 10 ); add_action( 'woocommerce_single_product_summary', 'woocommerce_output_product_data_tabs', 60 ); I also would like to make the pictures/text sticky as in this website: https://www.kustomdesigns.com.au/?product=mx-jersey my website //morenatural.nl/product/jojoba-olie-biologisch-koudgeperst/ I hope someone could help. Thanks already guys. Cheers, Henk
The following snippet is from a sidebar widget that lists "recent posts". Since its on the home page and I feature my lastest sticky post prominently on that page, I want to skip over the sticky in this loop. However, the post_not_in=sticky_posts has no effect. <?php $the_query = new WP_Query("showposts=$number&offset=1&order=ASC&post_not_in=sticky_posts"); while ($the_query->have_posts()) : $the_query->the_post(); $do_not_duplicate = $post->ID; ?>
I'm using a static home page, so my posts go to a different page. How can I pin a post to the top of the page the posts go to (not the home page)? Originally I thought it was as easy as using the edit page feature, so I typed what I wanted, but apparently when you change to a static home page and redirect your posts to a different page, it overrides what you wrote in the edit page.