- This topic has 16 replies, 4 voices, and was last updated 3 years, 5 months ago by Niklas.
-
AuthorPosts
-
November 9, 2020 at 9:28 am #1524204Niklas
I want to display the latest post in the header. For this purpose I have created an element with the position after_header_content. There I call the latest post with the function wp_get_recent_posts(). This also works. However, the permalink of the post always refers to the page itself and not to the post?
November 9, 2020 at 10:44 am #1524305LeoStaffCustomer SupportHi there,
This doesn’t sound like a theme related issue.
Perhaps a plugin like WP Show Posts (also developed by Tom) would help?
https://en-ca.wordpress.org/plugins/wp-show-posts/November 9, 2020 at 11:34 am #1524372NiklasHi Leo,
thanks for the quick answer. The wrong permalink only occurs when I place the latest post in a GP element, if I place the function in the content it works. In the GP element I call the function like this$recent_posts = wp_get_recent_posts( array( 'post_type' => 'post', 'numberposts' => 1, 'post_status' => 'publish', ) ); foreach($recent_posts as $post) { echo get_the_excerpt($post['ID']); echo get_permalink($post['ID']); }
This permalink of the get_the_excerpt() always refers to the page itself. get_permalink() works. This is strange.
November 9, 2020 at 1:35 pm #1524494TomLead DeveloperLead DeveloperThat’s strange. What if you add this in the loop?:
var_dump($post['ID']);
Does it output the correct ID?
November 10, 2020 at 2:10 am #1524974NiklasThis shows the correct ID.
November 10, 2020 at 3:48 am #1525072DavidStaffCustomer SupportHi there,
do you have any functions that may be affecting the post loop or the excerpt ?
November 10, 2020 at 5:29 am #1525141NiklasI have disabled several functions and plugins, the result is always the same. Maybe a similar problem is described here, unfortunately there is no solution:
https://wordpress.org/support/topic/read-more-buttons-below-posts-link-to-main-page/November 10, 2020 at 5:39 am #1525149DavidStaffCustomer SupportAny chance you can link us to a page where we can see the ‘broken’ post ?
November 10, 2020 at 5:50 am #1525163NiklasI can unlock the site for about 1 hour, I hope that’s enough:
November 10, 2020 at 5:56 am #1525172DavidStaffCustomer SupportIts requesting a login ? You can share login details in the Private Information field in your reply.
November 10, 2020 at 6:24 am #1525209NiklasSorry there was a short delay, now the page can be reached without login.
November 10, 2020 at 6:42 am #1525237DavidStaffCustomer SupportI am seeing 2 x Read More Links – 1 of which is incorrect ( current page ) and the other which has the correct link ? What changed ?
November 10, 2020 at 6:47 am #1525243Niklasthe first link comes from: get_the_excerpt($post[‘ID’]);
the second from: get_permalink($post[‘ID’]);November 10, 2020 at 9:54 am #1525737TomLead DeveloperLead DeveloperThis likely means the read more link that is filtered into the
get_the_excerpt()
function isn’t working correctly.You could try this:
function tu_disable_more_link() { return ''; } add_filter( 'excerpt_more', 'tu_disable_more_link', 999 ); get_the_excerpt($post['ID']); remove_filter( 'excerpt_more', 'tu_disable_more_link', 999 );
November 11, 2020 at 10:27 am #1527213NiklasThis is one way around the problem. I would just like to know why the links have different targets. But some things may remain mysterious.
-
AuthorPosts
- You must be logged in to reply to this topic.