Get random custom posts from a custom post type

You need to include setup_postdata($post); in your foreach line. Here’s some great demo code from the codex, adopted to fit your query: <ul> <?php global $post; $tmp_post = $post; $myposts = get_posts( ‘post_type=predic&numberposts=4&orderby=rand’ ); foreach( $myposts as $post ) : setup_postdata($post); ?> <li><a href=”https://wordpress.stackexchange.com/questions/74243/<?php the_permalink(); ?>”><?php the_title(); ?></a></li> <?php endforeach; ?> <?php $post = $tmp_post; … Read more

Row actions not showing? Why?

In display_rows() you are using the following code to print the ‘name’ column: echo ‘<td ‘.$attributes.’><strong><a href=”‘.$editlink.'” title=”Edit”>’.stripslashes($rec->name).'</a></strong></td>’; Nowhere do you call column_name(), which is the function you’ve defined to display the item’s and row actions: function column_name($item){ $actions = array( ‘edit’ => sprintf(‘<a href=”https://wordpress.stackexchange.com/questions/76517/?page=%s&action=%s&testimonial=%s”>Edit</a>’,$_REQUEST[‘page’],’edit’,$item[‘ID’]), ‘delete’ => sprintf(‘<a href=”https://wordpress.stackexchange.com/questions/76517/?page=%s&action=%s&testimonial=%s”>Delete</a>’,$_REQUEST[‘page’],’delete’,$item[‘ID’]), ); //Return the title contents return … Read more

How can I use a different default admin menu icon for custom post type?

add_action( ‘admin_head’, ‘custom_post_type_icon’ ); function custom_post_type_icon() { ?> <style type=”text/css” media=”screen”> #menu-posts-intranet-pages .wp-menu-image { background: url(“PATH TO SMALL ICON”) no-repeat 6px 6px !important; } #menu-posts-intranet-pages:hover .wp-menu-image, #menu-posts-intranet-pages.wp-has-current-submenu .wp-menu-image { background-position:6px -16px !important; } #icon-edit.icon32-posts-intranet-pages {background: url(“PATH TO BIG ICON”) no-repeat;} </style> <?php } This way is much better I believe as it also allows to … Read more

Changing the header on post listing page in admin area

To insert links at that position, you need the filter views_edit-POST_TYPE, replacing POST_TYPE by the slug of your CPT. Example: add_filter( ‘views_edit-portfolio’, ‘custom_list_link_wpse_79975’ ); function custom_list_link_wpse_79975( $views ) { $views[‘dashboard’] = ‘<a href=”‘ . admin_url(‘index.php’) . ‘”>Dashboard</a>’; // $views[‘another-view’] = ‘<a href=”#”>Contact</a>’; return $views; } Results in: The second question should have been a separate … Read more

Redirect to post with only post ID in the URL vs post_type/post ID

I used the following plugin lately: https://github.com/kasparsd/numeric-shortlinks to get post ID based shortlinks, like http://domain.com/123. That worked very well for me, with a couple of custom post types too. On a sidenote, I’m not sure about your permalink structure, especially because %post_id% and %postname% are both uniquely referring to the same post, but on the … Read more