Forum
Made custom post slug but meta is not working now
Hello,
About a week ago I opened a thread about creating a post slug by using a custom field. That is working perfectly, but now my meta_head is not outputting anything.
My top.php
:
<?php
if (perch_layout_has('blog-post')) {
perch_blog_post_meta(perch_get('s'));
} else if (perch_layout_has('blog-index')){
echo '<title>' . 'Blog' . '</title>';
} else if (perch_layout_has('blog-archief')){
echo '<title>' . 'Archief' . '</title>';
} else{
echo '<title>' . perch_pages_title(true) . '</title>';
}
?>
When using perch_get('s') it outputs nothing.
I use /blog/<perch:blog id="customUrlSlug" type="hidden" />
as a path to my posts, which is working fine.
When using perch_get('customUrlSlug') it outputs meta tags from 10! posts.
I get my post on post.php
like this:
<?php
# get the post
$post = perch_blog_custom(array(
'filter' => 'customUrlSlug',
'match' => 'eq',
'value' => perch_get('s'),
'skip-template' => 'true',
'return-html' => 'true',
));
?>
I tried using:
if (perch_layout_has('blog-post')) {
perch_blog_post_meta(array(
'filter' => 'customUrlSlug',
'match' => 'eq',
'value' => perch_get('s'),
'skip-template' => 'true',
'return-html' => 'true',
));
But that is also outputting meta tags for 10 posts.
How could I get the blog post meta for a single post?
Those functions are filtering on the built in
postSlug
. If you're not usingpostSlug
then they won't work.A workaround would be to find the post with your custom slug, get the default
postSlug
from that, and then pass that into the meta functions.Is that not what I am trying here:
?
Hello Mike,
I don't think you can filter using
perch_blog_post_meta()
: https://docs.grabaperch.com/functions/blog/perch-blog-post-meta/$default_slug
has to bepostSlug
.The biggest advantage of
perch_blog_post_meta()
, besides convince, is caching, but otherwise you can do the same thing withperch_blog_custom()
.So you can use:
It may be wise to check what
perch_get()
does:Thanks a lot Hussein,
Works like a charm. I didn't know I could use blog_custom for that purpose, but it is pretty logical. I will definitely check out your blog post.
Mike