New answers tagged

0

I assume that you're making your custom post type in a plugin if you mean for it to work with any theme. In that case, I would suggest building your templates in your plugin, and call all your meta data there. Example: /* Filter the single_template with our custom function*/ add_filter('single_template', 'my_custom_template'); function my_custom_template(...


4

I'd suggest to not add layout, but MarkUp and offer an option to override it. The best way to do this would be to add to a hook that your users can add to their themes templates. // Theme template file do_action( 'hotel_rooms' ); // Your plugin hooks in there: add_action( 'hotel_rooms', 'callback' ); function callback() { echo "I am displaying details ...


2

get_the_category() retrieves the current post categories. To get all categories you should use get_categories() instead


0

Change $loop = new WP_Query( array( 'post_type' => 'portfolio', 'posts_per_page' => -1 ) ); to e.g. $loop = new WP_Query( array( 'post_type' => 'portfolio', 'posts_per_page' => 9 ) ); If you set posts_per_page to -1 you will always pull all available posts. Hence, no pagination will show up since all posts are already shown on the first page.


0

Same issue as the OP. As @sviriden noted in his answer, the problem is that the main query is not including your custom post type in the wp_posts.post_type IN clause. I tracked down the issue in class-wp-query.php to these lines: if ( 'any' == $post_type ) { $in_search_post_types = get_post_types( array( 'exclude_from_search' => false ) ); ...


0

First, take a look at this: https://developer.wordpress.org/reference/classes/wp_query/ You can filter by querying by post type, or in a single query (code between /* */). <?php //This is the first query $query_A = array( 'post_type' => 'post_type_A', 'post_status' => 'publish', //'cache_results' => true, 'posts_per_page' =&...


0

Try this <?php $post_type = "post"; $taxonomy = "category"; $terms = get_terms( array( 'taxonomy' => $taxonomy, 'hide_empty' => 0, 'hierarchical'=> 1, ) ); echo '<ul>'; foreach($terms as $term): $term_id = $term->term_id; $term_name = $term->name; $query = array( 'post_type' =&...


0

Changes it so it works. <?php $i = 1; $icount = 1; ?> <?php while ( have_posts() ) : the_post(); if ($icount < 11) { if ($i % 5 == 0) { echo '<div class="col5x2">'; include 'modules/projects/small-square.php'; ...


1

get_post_format() returns the post format slug for either the current post, when used inside a loop, or a given post, when a WP_Post object or an integer post ID is passed to it as a parameter. So, if you're using the function in a posts loop, then you can use it like this, while ( have_posts() ) { the_post(); if ( 'gallery' === get_post_format() ) { ...


0

To obtain and get the author ID outside the loop: global $post; $author_id = $post->post_author; Then use get_the_author_meta('field_name', $author_id) remember if you are fetching posts id in loop and accessing author out side loop then it will only provide data of last post id in loop


0

Hopefully this wil help: $args= array( 'post_type' =>'any', 'post_status' => 'publish', 'order' => 'ASC', 'posts_per_page' => '-1' ); $posts = new WP_Query($args); $posts = $posts->posts; foreach($posts as $post) { switch ($post->post_type) { case 'page': // get the author's id through the post or ...


0

If there are no values in the array you can try the following approach: $last_categories = get_categories( array( 'taxonomy' => 'product_cat', 'parent' => $sub_category->cat_ID ) );


Top 50 recent answers are included