Programmatically add posts from specific category to menu

I’m not 100% sure if I get you right, but maybe this will solve your problem: add_filter( ‘wp_nav_menu_items’, ‘fx_user_menu’, 10, 2 ); function fx_user_menu( $items, $args ) { if ($args->theme_location == ‘primary’) { $myposts = get_posts( array( ‘category’ => <YOUR CATEGORY ID GOES HERE>, ‘posts_per_page’ => 5 ) ); foreach ( $myposts as $post ) … Read more

Showing recent post of category in page

Here is a start. This is how I display related posts from the category the post are in. You will just need to add your own loop and CSS Create a template called content-related.php Inside that paste the following code <?php /** * The default template for displaying realted posts * * @package WordPress * … Read more

List all native posts in template page?

There is nothing wrong in your query, but there is some code (a plugin?) that remove from results the posts in the category having term id 1 or 4. (Normally category with term id 1 is ‘uncategorized’) You can notice that looking at request performed AND ( wp_posts.ID NOT IN ( SELECT object_id FROM wp_term_relationships … Read more

post type slug vs page slug

You can created a post template to display the CPT post details (i.e. videos/my-video) and you can create an archive template to display a list of posts (i.e. videos/). To create a post template in a plugin, add the following to the plugin: function include_templates( $template_path ) { if ( get_post_type() == ‘videos’ ) { … Read more

Optimize CPT-function with a loop

Finally I got the solution. One of the major problems was the usage of “get_post_custom” for fetching the database. I used “get_post_meta” instead and it was a lot easier to work with the array that was created by that function. I am sure that it would have been possible to do it with the first … Read more

Rand post related question

This is more a generic PHP question, but for what it’s worth: if ( empty( $_SESSION[‘seed_time’] ) ) $_SESSION[‘seed_time’] = time(); if ( empty( $_SESSION[‘seed’] ) || time() > ( $_SESSION[‘seed_time’] + 30 * MINUTE_IN_SECONDS ) ) { // Seed session is empty, or session time is older than 30 minutes, generate new seed $_SESSION[‘seed’] … Read more

WordPress query portfolio posts

You can simply just add the cat or category_name parameter to your query. When using cat, you should use the category ID, and should you use category_name, it should be the slug of the category, not the name. Change <?php $tarali_query = new WP_Query(‘posts_per_page=”.$nbmax.”&ignore_sticky_posts=1&paged=’.$paged); ?> to <?php $tarali_query = new WP_Query(‘posts_per_page=”.$nbmax.”&cat=CATID&ignore_sticky_posts=1&paged=’.$paged); ?> For futher reading: … Read more