Custom post type archive not regarding ‘posts_per_page’ => -1

WP_Query is for secondary loops. That is to say that it’s completely independent from the page’s default $wp_query. I suspect that it’s not working because you aren’t referencing your new WP_Query object on the loop. To do that, you’d do this: if( $all_sports->have_posts() ) : while( $all_sports->have_posts() ) : $all_sports->the_post(); // do stuff endwhile; endif; … Read more

How to make post sticky in the admin page?

“Admin Stickies” for custom post types: To support sticky custom posts in the backend, you can use the following code snippet in your functions.php file in the current theme directory or in your custom plugin: /** * Set admin stickies for the ‘foodmenu’ custom post type */ add_action( ‘init’, function() { if( function_exists( ‘wpse_cpt_stickies’ ) … Read more

Check if author or current user has posts published

Using get_posts or WP_query with similar $args: $args = array( ‘post_type’ => ‘your_custom_post_type’, ‘author’ => get_current_user_id(), ); $wp_posts = get_posts($args); if (count($wp_posts)) { echo “Yes, the current user has ‘your_custom_post_type’ posts published!”; } else { echo “No, the current user does not have ‘your_custom_post_type’ posts published.”; }

Function error – Use of undefined constant ‘pre_get_posts’ – assumed ‘‘pre_get_posts’’

Those look like curly apostrophes, not straight… try changing them to straight (all of them in your code) like this: function add_custom_types_to_tax( $query ) { if ( is_category() || is_tag() && empty( $query->query_vars[‘suppress_filters’] ) ) { // Get all your post types $post_types = get_post_types(); $query->set( ‘post_type’, $post_types ); return $query; } } add_filter( ‘pre_get_posts’, … Read more

Customize permalink when creating a post

This can be done using the wp_insert_post_data hook. function house_post_slug( $data ) { if ( $data[‘post_type’] == ‘houses’ ) { $permalink = ”; if ( isset ( $_POST[‘ACF Code Field’] ) ) { $permalink = $_POST[‘ACF Code Field’]; } if ( isset ( $_POST[‘post_title’] ) ) { $permalink .= ‘-‘ . $_POST[‘post_title’]; } $data[‘post_name’] = … Read more

How to load custom post archives sub-pages with ajax?

you might use the $.load and preventDefault() from jQuery. Assugming that you have .page-link link class on each url in pagination and you have all the posts in the #content div following code can help you to load the posts in that div on that particular page. $(“body”).on(“click”, “a.page-link”, function(e) { e.preventDefault(); $(“#content”).load($(this).attr(“href”) + ” … Read more