In WordPress, Custom Post Types do not have Sticky functionality as a core feature. It is possible, I'm sure, to create it in certain cases—and I'm working on a project that requires it for archive-{customposttype}.php
templates.
I have downloaded and installed a plugin, called Sticky Custom Post Types, which I read in this article could be used along with a little bit of PHP to get_option( 'sticky_posts' ) and reconfigure the array of the query currently being executed.
I know that the plugin works because using if (!is_sticky()) {et cetera}
within the loop allows me to alter the output of the sticky (custom post type) posts.
I haven't been able to successfully implement the code from the article—the order doesn't seem to change at all when I place it at the top of my archive-{customposttype}.php
template, nor have I been able to make it work through several other attempts. This is probably because I'm not very adept at PHP.
Another thing I tried is creating a new query, specifying that I want only sticky posts (which worked at showing me only sticky posts); trying to store that query in a variable, then calling wp_reset_query()
, then creating another query specifying that I don't want sticky posts, trying to store that in a variable, calling wp_reset_query()
again; and then merging the two query arrays with array_merge()
.
Unfortunately my various implementations of this either broke the page, or succeeded at doing absolutely nothing, or only showed the second query's output... and I deleted them out of scorn.
I don't know if I'm going about this in the right way at all, really; and I'm sure plenty of people have confronted and overcome this issue. If anyone has any advice or code snippets to help me implement this feature, it'd be greatly appreciated.
To reiterate for the sake of clarity, I'm attempting to show sticky posts at the top of my archive pages for custom post types.