admin管理员组

文章数量:1194359

I can't wrap my head around this and yes I've tried to flush the permalinks etc...

I've never encountered this before and a week ago it worked - I have not changed any code and it works on another website with the exact same theme.

anyway, I have a few custom post types and the problem is affecting all of these.

For example, let's take news.

In single-news.php I have a list showing the latest 10 news.

<?php
            $query = new WP_Query(array(
            'post_type' => 'news',
            'post_status' => 'publish',
            'posts_per_page' => 10,
            'post__not_in' => [get_the_ID()],
            ));
                
            while ($query->have_posts()) {
                $query->the_post();

                $newspost = '<li><a href="'.get_permalink(get_the_ID()).'">'.get_the_title().'</a></li>';

                echo $newspost;
                
            }
            wp_reset_query();

get_permalink(), get_the_permalink() or the_permalink, nothing works.

The title works, get_the_ID() shows the correct post ID if I echo it, but the URL just returns site/news and not the url to the post.

For another post type, services, it just returns site/services

What's wrong here? I'm sure it's not the code, and I've tried deactivating plugins as well with no luck.

本文标签: Get permalink in custom post type loop doesn39t work