Hi, I created a custom post type called &quot;news&quot; and custom categories called &quot;news_category&quot; to have them categorized. I want to list &quot;news&quot; posts that belong to one of these categories. In this case the category id is 83. This is my code: &lt;?php $news = get_posts( array(     'post_type'      =&gt; 'news',     'category' =&gt; 83 ) );   if ( $news ) {     foreach ( $news as $post ) {         setup_postdata( $post );         the_title();     }     wp_reset_postdata(); } ?&gt;  This will produce nothing despite category ID is correct. If I use a 0 instead then it lists all posts regardless of their category but any other number will list nothing. Why is that? By the way, I created the new taxonomy with this plugin: Custom post types Thank you. EDIT:               &lt;?php     $news = get_posts(     array(         'posts_per_page' =&gt; -1,         'post_type' =&gt; 'news',         'tax_query' =&gt; array(                 'taxonomy' =&gt; 'news_category',                 'field' =&gt; 'term_id',                 'terms' =&gt; 82,             ),         ) );      $postslist = get_posts( $news );         foreach ($postslist as $crap) {?&gt;          &lt;a href=&quot;&lt;?php $crap-&gt;title; ?&gt;&quot;&gt;&lt;?php $crap-&gt;title; ?&gt;&lt;/a&gt;       &lt;?php }?&gt;
43594
I want to display custom type posts from a custom taxonomy category so I did this: $news = get_posts( array(     'posts_per_page' =&gt; -1,     'post_type' =&gt; 'news',     'tax_query' =&gt; array(             'taxonomy' =&gt; 'news_category',             'field' =&gt; 'term_id',             'terms' =&gt; 82,         ),     ) );  $postslist = get_posts( $news );      foreach ($postslist as $crap) { ?&gt;      &lt;a href=&quot;&lt;?php $crap-&gt;title; ?&gt;&quot;&gt;&lt;?php $crap-&gt;title; ?&gt;&lt;/a&gt; &lt;?php }?&gt;  I get nothing from this. Why is that? I double checked the category ID and its correct. Also, I used the Custom post types plugin to register the custom taxonomy.
11669
WordPress allows adding descriptions to Custom Post Types whenever it's registered. ( . I would like to output that title on the Admin Landing Page ( View All Post Type ) preferably underneath the title. I've looked into /wp-admin/edit.php but I'm not sure if the filter presented is usable in this case ( and thus it may not be possible to do ).   is where it looks like the actual title gets set. Is is possible / is there a way to filter into it and add my post type description?
10789
I'm developing a Custom Post Type plugin, which works fine in dev. Now that I've moved it to production, I'm getting a 404 when I try to display the template for the CPT.   So, two questions:  1- Is there some mechanism to determine the path WP took to get through the hierarchy?  2- Why wouldn't it just give me the single or index page?  I've dumped $wp_query and a stacktrace at the end of the 404. Here's part of what I found:  [query] =&gt; Array     (         [page] =&gt;          [pagename] =&gt; refletters/proximity     )  [request] =&gt; SELECT   wp_posts.* FROM wp_posts  WHERE 1=1  AND (wp_posts.ID = '0') AND wp_posts.post_type = 'page'  ORDER BY wp_posts.post_date DESC  [posts] =&gt; Array     (     )  [queried_object] =&gt;  [queried_object_id] =&gt; 0   And the stack trace:  2013-04-27 22:16:41 - 24.52.197.40 - TRACE - index.php - 404.php[39] -      wordpress/wp-content/themes/notoriousconsultant/404.php[39] - aaLog-&gt;logtrace     wordpress/wp-includes/template-loader.php[50] - include     wordpress/wp-blog-header.php[16] - require_once     wordpress/index.php[17] - require   Thanks for your help.
102168
I'm trying to create a archive list with only my "normal" post format articles (not link, aside, quote, etc formats).  How would I implement has_post_format( 'standard' ), or something similar, into the code below?  I haven't been able to find a query for get_posts that only requests specific format types.  &lt;?php         // Get the posts     $myposts = get_posts('numberposts=-1&amp;orderby=post_date&amp;order=DESC');      ?&gt;  &lt;?php foreach($myposts as $post) : ?&gt;     &lt;?php         // Setup the post variables     setup_postdata($post);      $year = mysql2date('Y', $post-&gt;post_date);     $month = mysql2date('n', $post-&gt;post_date);     $day = mysql2date('j', $post-&gt;post_date);     ?&gt;  &lt;p&gt;     &lt;span class="the_article"&gt;         &lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;     &lt;/span&gt;     &amp;nbsp;&amp;nbsp;&amp;nbsp;     &lt;span class="the_day"&gt;         &lt;?php the_time('j F Y'); ?&gt;     &lt;/span&gt; &lt;/p&gt;  &lt;?php endforeach; ?&gt;   My php skills are at the beginner level at best, so any help would be much appreciated.
59096
I found this problem on Wordpress Support and the topic unfortunately is now closed.  I have this same issue... (read below)    We have created a site where members can recommend things like favourite books, movie, songs, etc. For this problem I will use the Movies page as an example.  The "Movies" page is ultimately a custom page template that asks wordpress to display a random list of ALL posts that have been given the category "movies" (category 31). It displays the title of these movies in random order using the code below.  &lt;?php  $rand = new WP_Query("cat=31&amp;showposts=-1&amp;orderby=rand");  while($rand-&gt;have_posts()) : $rand-&gt;the_post(); ?&gt;" rel="bookmark" title="Permanent Link to &lt;?php the_title_attribute(); ?&gt;"&gt;&lt;?php the_title(); ?&gt; &lt;?php endwhile; ?&gt;   Problem is the list is getting rather long and I would like to split it up into two or more pages of about 10 movies each. To achieve this, I have used the code below.  &lt;?php  $page = (get_query_var('paged')) ? get_query_var('paged') : 1;  query_posts("cat=31&amp;orderby=rand&amp;showposts=10&amp;paged=$page");  while ( have_posts() ) : the_post()  ?&gt;" rel="bookmark" title="Permanent Link to &lt;?php the_title_attribute(); ?&gt;"&gt;&lt;?php the_title(); ?&gt; &lt;?php endwhile; ?&gt;   But there is a problem because although it splits up the data into pages of 10 posts each (paginates), it fails to include a new set of 10 posts on page 2 and so forth. In other words, because it is listing things in a random order, it just goes out and gets another 10 random posts (or in this case movie titles). As a result, we have some repeated movie title posts instead of a new set of 10 random movie titles on page 2, etc.  My question is - what can I add to this code to get wordpress to "remember" which random 10 posts it included on page 1, and then have it get a new set of 10 posts to put on pages 2, 3, etc. until all posts are displayed. I would like there to be only one occurrence of a post per page when sorted randomly in sets of 10.
51115
I'm trying to rewrite my url for a custom_post_type named wr_events with one of its custom_taxonomy terms from event_type  add_action('init', 'wr_events');  function wr_events() {       register_taxonomy(         'event_type',         'wr_event',         array(             'label' =&gt; 'Types',             'singular_label' =&gt; 'Typ',             'hierarchical' =&gt; true,             'query_var' =&gt; true,             'rewrite' =&gt; array('slug' =&gt; 'events'),         )     );      $labels = array(         'name' =&gt; _x('Events', 'post type general name'),         'singular_name' =&gt; _x('Event', 'post type singular name')     );      $args = array(         'labels' =&gt; $labels,         'public' =&gt; true,         'publicly_queryable' =&gt; true,         'show_ui' =&gt; true,         'query_var' =&gt; true,         'capability_type' =&gt; 'post',         'hierarchical' =&gt; false,         'menu_position' =&gt; null,         'supports' =&gt; array('title','editor','thumbnail', 'excerpt'),         'rewrite' =&gt; array(             //'slug' =&gt; 'event',             'slug' =&gt; 'events/%event%',             'with_front' =&gt; false         ),         'has_archive' =&gt; 'events'     );       register_post_type( 'wr_event' , $args );     flush_rewrite_rules(); }  add_action('save_post', 'save_details');  add_filter('post_type_link', 'events_permalink_structure', 10, 4); function events_permalink_structure($post_link, $post, $leavename, $sample) {     if ( false !== strpos( $post_link, '%event%' ) ) {         $event_type_term = get_the_terms( $post-&gt;ID, 'event_type' );         $post_link = str_replace( '%event%', array_pop( $event_type_term )-&gt;slug, $post_link );     }     return $post_link; }   So in my case my taxonomy terms would be "workshops" or "lectures" etc. url/events/lectures or url/events/workshops lists all my posts related to this "category", url/events shows a custom archive for all my events. -> this is just what I want however the only thing not working is the complete url to the custom-post itself …  url/events/lectures/post-name - throws a 404!  Any idea why this is happening? My events_permalink_structure() function seems to work correctly as it replaces my permalinks exaclty the way I want.   I installed the "Rewrite Analyzer" Plugin and it  "Regex is empty" for wr_event.  I've also tried to flush the Rewrite Rules by visiting the permalink settings. However no effect.
96555
i create a custom page to display loop of cpt with custom field.   I need to add a numberic pagination and i try with this code but not work.  Functions.php  function pagination_bar() {     global $wp_query;      $total_pages = $wp_query-&gt;max_num_pages;      if ($total_pages &gt; 1){         $current_page = max(1, get_query_var('paged'));          echo paginate_links(array(             'base' =&gt; get_pagenum_link(1) . '%_%',             'format' =&gt; '/page/%#%',             'current' =&gt; $current_page,             'total' =&gt; $total_pages,         ));     } }   custompage.php  &lt;!--Loop Salmi--&gt; &lt;?php $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1; $loop = new WP_Query( array( 'post_type' =&gt; 'salmi',         'posts_per_page' =&gt; 15,         'paged'          =&gt; $paged ) ); while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post(); ?&gt;      &lt;!--Colonne Contenuto --&gt;     &lt;div class="salmicpt"&gt;         &lt;div class="wpb_column vc_column_container td-pb-span8"&gt;             &lt;div class="titlecpt"&gt;&lt;?php the_title(); ?&gt;&lt;/div&gt;         &lt;/div&gt;         &lt;div class="wpb_column vc_column_container td-pb-span4"&gt;             &lt;?php if( get_field('audio_salmi') ): ?&gt;                 &lt;a href="&lt;?php the_field('audio_salmi'); ?&gt;" &gt;&lt;img src="mysite.com/wp-content/uploads/cuffia-cpt-e1481533293805.png" alt="Ascolta" title="Ascolta" /&gt;&lt;/a&gt;             &lt;?php endif; ?&gt;             &lt;?php if( get_field('salmi_pdf') ): ?&gt;                 &lt;a href="&lt;?php the_field('salmi_pdf'); ?&gt;" &gt;&lt;img src="mysite.com/wp-content/uploads/freccia-32.png" alt="Scarica il PDf" title="Scarica il PDF" /&gt;&lt;/a&gt;             &lt;?php endif; ?&gt;         &lt;/div&gt;         &lt;div style='clear:both'&gt;&lt;/div&gt;&lt;hr class="style-one" /&gt;     &lt;/div&gt;     &lt;nav class="pagination"&gt;         &lt;?php pagination_bar(); ?&gt;     &lt;/nav&gt;  &lt;?php endwhile; wp_reset_query(); ?&gt;    Where is wrong?? Thanks
54899
I'm trying to get my news page to display content from one category only (number 3) but I cant seem to get it to work. Instead of just displaying posts from category 3 it displays posts from all category's.  Here is my code:  &lt;?php get_header(); ?&gt;              &lt;div class="content news_page"&gt;                         &lt;h1&gt;Latest News&lt;/h1&gt;                              &lt;?php $args = array(                             'post_type' =&gt; 'post' ,                             'orderby' =&gt; 'date' ,                             'order' =&gt; 'DESC' ,                             'posts_per_page' =&gt; 6,                             'category'         =&gt; '3',                             'paged' =&gt; get_query_var('paged'),                             'post_parent' =&gt; $parent                        ); ?&gt;                        &lt;?php query_posts($args); ?&gt;                            &lt;?php if ( have_posts() ) : ?&gt;                             &lt;?php while ( have_posts() ) : the_post(); ?&gt;                                  &lt;div class="large-4 medium-4 small-12 columns"&gt;                                     &lt;div class="latest_news_cont"&gt;                                     &lt;a href="&lt;?php the_permalink() ?&gt;"&gt;&lt;?php the_post_thumbnail(); ?&gt;&lt;/a&gt;                                      &lt;a href="&lt;?php the_permalink() ?&gt;"&gt;&lt;h5&gt;&lt;?php the_title(); ?&gt;&lt;/h5&gt;&lt;/a&gt;                                     &lt;?php the_excerpt(); ?&gt;                                     &lt;p style="text-align:center;"&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" class="readmore_news"&gt;Read more&lt;/a&gt;&lt;/p&gt; &lt;br&gt; &lt;div class="clear"&gt;&lt;/div&gt;                                        &lt;/div&gt;                                     &lt;/div&gt;                              &lt;?php endwhile; ?&gt;                         &lt;?php endif; ?&gt;   &lt;div class="clear"&gt;&lt;/div&gt;              &lt;/div&gt;&lt;!--end of content--&gt;    &lt;div class="clear"&gt;&lt;/div&gt;  &lt;?php get_footer(); ?&gt;
23832
i try to run a custom post type query to match following criteria: sort movies first by year in descending order, after that ("inside" the year order) by title alphabetically.      desired output: movie title A, 2006 movie title Z, 2006 ... movie title A, 1996 movie title Z, 1996    i use the following code:  $wp_query = new WP_Query(); $wp_query-&gt;query( array( 'post_type' =&gt; 'movies',                        'distribution' =&gt; 'companyA',                        'meta_key' =&gt; 'year',                       'orderby' =&gt; 'meta_value_num title',                         'order' =&gt; 'DESC',                        'posts_per_page' =&gt; -1,                        'post_status' =&gt; 'publish', ));   i tried several things but i can only get this "inverse" result:  movie title A, 1996 movie title Z, 1996 ... movie title A, 2006 movie title Z, 2006      if i change DESC, ASC it only changes the title sorting. but i need to apply it to the year and not to the title.  is it the right way to use two orderby values? or do i have to use a meta_query or custom SQL ?   thx in advance!  Here is the resulting SQL Query from $GLOBALS['wp_query']-&gt;request    SELECT&nbsp;wp_posts.* FROM&nbsp;&nbsp;&nbsp;wp_posts &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;INNER&nbsp;JOIN&nbsp;wp_term_relationships &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ON&nbsp;(&nbsp;wp_posts.id&nbsp;=&nbsp;wp_term_relationships.object_id&nbsp;) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;INNER&nbsp;JOIN&nbsp;wp_postmeta &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ON&nbsp;(&nbsp;wp_posts.id&nbsp;=&nbsp;wp_postmeta.post_id&nbsp;) WHERE&nbsp;&nbsp;1&nbsp;=&nbsp;1 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AND&nbsp;(&nbsp;wp_term_relationships.term_taxonomy_id&nbsp;IN&nbsp;(&nbsp;24&nbsp;)&nbsp;) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AND&nbsp;wp_posts.post_type&nbsp;=&nbsp;'movies' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AND&nbsp;(&nbsp;wp_posts.post_status&nbsp;=&nbsp;'publish'&nbsp;) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;AND&nbsp;(&nbsp;wp_postmeta.meta_key&nbsp;=&nbsp;'year'&nbsp;) GROUP&nbsp;&nbsp;BY&nbsp;wp_posts.id ORDER&nbsp;&nbsp;BY&nbsp;wp_postmeta.meta_value&nbsp;+&nbsp;0, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;wp_posts.post_title&nbsp;DESC&nbsp;
69974
I got a paged loop that pulls in 4 posts per page from custom post type. It works great, with the only downside that the pagination wont go over the page/20 everything after that is 404, and the posts_nav_link won't show the next arrow at all. Like the pages just aren't there.  In total there are 119 published posts in the custom post type. If I change posts_per_page to, say 6, then I get access to more of the posts from the end, but it also stops at the page/20.  On the production site the pagination stops at 21, I guess because the live database has more entries.  I got the "Blog pages show at most" setting set to 6.  Here's the loop I'm using:  &lt;?php $paged = get_query_var('paged') ? get_query_var('paged') : 1; $args  = array(     'posts_per_page' =&gt; 4,     'orderby'        =&gt; 'modified',     'post_type'      =&gt; "projekte",     'paged'          =&gt; $paged ); $custom_query = new WP_Query($args); $c = 0; while($custom_query-&gt;have_posts()) :     $custom_query-&gt;the_post();     ?&gt;     &lt;article&gt;...&lt;/article&gt;     &lt;?php endwhile; wp_reset_postdata(); // reset the query ?&gt;   I've gone through the functions.php a million times looking for a some limiting get_pre_posts filter but there's nothing I can see.  I also got an error log setup and nothing is returned there, I've tested it that it works.  Any suggestions?
4944
I am having trouble working with WordPress rewrite rules, and could use some help.  I have a custom post type called _shows_.  All shows have a single custom taxonomy category _show-category_. A _show_ will never have more than one _show-category_.  I would like my urls to route in this manner:  www.mysite.com/shows/  =&gt;  archive-shows.php  www.mysite.com/shows/%category%/ =&gt; taxonomy-show-category.php  www.mysite.com/shows/%category%/%postname%/ =&gt; single-shows.php   So as a real world example, lets say we have a _show-category_ "Foo" and a _show_ post titled "Bar" that has "Foo" as it's _show-category_. I would expect my WordPress app to look like this:  www.mysite.com/shows/foo/ =&gt; shows all posts under the foo category www.mysite.com/shows/foo/bar =&gt; shows the indivual post   I try to avoid plugins when possible, but am open to any solution.
90821
If I have a loop running from a category query like :  &lt;?php $the_query = new WP_Query('cat=1&amp;showposts=50&amp;orderby=title&amp;order=asc');?&gt; &lt;ul&gt; &lt;?php while ($the_query-&gt;have_posts()) : $the_query-&gt;the_post();?&gt; &lt;li&gt;.. &lt;/li&gt;&lt;?php wp_reset_query(); ?&gt; &lt;?php endwhile; ?&gt; &lt;/ul&gt;   How would I create an if clause that breaks the list at a certain interval, and starts a new one. So for example at the 10th post, return a &lt;/ul&gt; and start a new one &lt;ul&gt; at 11.  This is incorrect but to illustrate my objective:  &lt;?php $count =0;     while($count &lt;=50){         if ($count == 9){             echo "&lt;li&gt;&lt;a href='&lt;?php the_permalink(); ?&gt;'&gt;                       &lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;";             }          elseif ($count == 10){         echo "&lt;ul&gt;&lt;li&gt;&lt;a href='&lt;?php the_permalink(); ?&gt;'&gt;                           &lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt;";         }         else {         echo "&lt;li&gt;&lt;a href='&lt;?php the_permalink(); ?&gt;'&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/li&gt;";         }   What is the correct way to include this logic into the loop?
29752
I am trying to order posts by tag count. I want to order posts with no tags first and posts with highest count last.  I tried and got posts with no tags only.       $tags = get_tags();     $tag_ids = wp_list_pluck( $tags, 'term_id' );      $args1 = array (        'orderby'          =&gt; 'DEC',        'post_type'        =&gt; 'post',        'pagination'       =&gt; true,        'posts_per_page'   =&gt; '1',        'tag__not_in'      =&gt;  $tag_ids,        'meta_key'         =&gt; '_thumbnail_id',     );   How do I order posts based on the tags count?
81723
Hi i'm using the code below to call post from a certain Category under certain post types, But how do i style it so that i can make the first post different from the rest of the post.  &lt;?php $queryObject = new  Wp_Query( array(         'showposts' =&gt; 4,         'post_type' =&gt; array('pretty-little-liars', 'revenge', 'once-upon-a-time'),         'category_name' =&gt; celebrity,             'orderby' =&gt; 1,         )); // The Loop! if ($queryObject-&gt;have_posts()) { ?&gt;  &lt;?php while ($queryObject-&gt;have_posts()){     $queryObject-&gt;the_post();     ?&gt;  &lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php printf(__( 'Read %s', 'wpbx' ), wp_specialchars(get_the_title(), 1)) ?&gt;"&gt;                     &lt;?php the_post_thumbnail('video-post'); ?&gt;                     &lt;/a&gt;  &lt;?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?&gt;                 &lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;   &lt;?php } ?&gt; &lt;?php wp_reset_postdata(); } ?&gt;
37578
Interesting challenge. I was given a piece of code earlier, which I have modified as follows for the Posts page.  /* add time stamp */ add_filter('manage_posts_columns', 'posts_columns', 5); function posts_columns($defaults){     $defaults['your_date_col'] = __('Date');     $defaults['week_number'] = __('Wk#');     $defaults['week_in_quarter'] = __('Wk/Qtr');     return $defaults; } add_action('manage_posts_custom_column', 'posts_custom_columns', 5, 2); function posts_custom_columns($column_name, $id){     if($column_name === 'your_date_col'){     echo the_date('d M'),' ',the_time('Ha');     }     if($column_name === 'week_number'){     echo 'Here: ',the_date();     } }   Strangely, although the date format that I have given shows up in the first column ("your_date_col"), only "Here: " shows up in the second column ("week_number"). Any suggestions as to why the_date function doesn't work in the second column?
54438
I'm using this code to list the image attachments of a post:        &lt;select name="chb_homes_for_sale_specifics_floor_plan" style="width:100%;"&gt;         &lt;option value=""&gt;Select&lt;/option&gt;         &lt;?php         $args = array(             'numberposts'     =&gt; -1,             'orderby'         =&gt; 'menu_order',             'order'           =&gt; 'ASC',             'post_type'       =&gt; 'attachment',             'post_parent'     =&gt; $post-&gt;ID,             'post_mime_type' =&gt; 'image'         );         $image = get_posts($args);         if($image) {             foreach($image as $key =&gt; $data) : ?&gt;                  &lt;option value="&lt;?php echo $data-&gt;ID; ?&gt;"&gt;&lt;?php echo $data-&gt;post_title; ?&gt;&lt;/option&gt;              &lt;?php endforeach;         }         ?&gt;       &lt;/select&gt;   But what I'm showing currently is the attachment post_title but I want to show the file name instead. I could maybe use get attachment URL then parse the URL to get the file name but was wondering if there is a ready made way in WordPress to get the file name.
14773
I created a custom post type:  register_post_type('sample_post_type',array(     'labels' =&gt; array(         'name' =&gt; _x('Sample Posts', 'post type general name'),         'singular_name' =&gt; _x('Sample Post', 'post type singular name')     ),     'public' =&gt; true,     'show_in_nav_menus' =&gt; false,     'exclude_from_search' =&gt; true ));   How can i disable the single post view for this specific post type? Displaying a simple 404 is fine, or redirecting to the homepage. This is inside a plugin, so i can't create a single-sample_post_type.php file to setup an empty page.