【问题标题】:Calling meta data in wordpress在 wordpress 中调用元数据
【发布时间】:2013-08-30 17:34:33
【问题描述】:

所以基本上我正在尝试编辑一个名为 Showbiz 的插件。他们从帖子中调用标准元数据,如标题、作者、日期,如下所示:

$title = $this->getValue("title");
$alias = $this->getValue("alias");
$urlImage = $this->imageUrl;
$text = $this->getValue("slide_text");

$link = $this->getValue("link");
if(empty($link))
    $link = "#";

$date = $this->getValue("date");

$dateModified = $this->getValue("date_modified");
$excerpt = $this->getValue("excerpt");

$youtubeID = $this->getValue("youtube_id");
$vimeoID = $this->getValue("vimeo_id");
$authorName = $this->getValue("author_name");
$numComments = $this->getValue("num_comments");
$catList = $this->getValue("catlist");
$tagList = $this->getValue("taglist");
$postID = $this->id;

//replace the items in the html
$html = $this->replacePlaceholder("title", $title, $html);
$html = $this->replacePlaceholder("id", $postID, $html);
$html = $this->replacePlaceholder("alias", $alias, $html);
$html = $this->replacePlaceholder("name", $alias, $html);
$html = $this->replacePlaceholder("image", $urlImage, $html);
$html = $this->replacePlaceholder("content", $text, $html);
$html = $this->replacePlaceholder("link", $link, $html);
$html = $this->replacePlaceholder("date", $date, $html);
$html = $this->replacePlaceholder("modified_date", $dateModified, $html);
$html = $this->replacePlaceholder("excerpt", $excerpt, $html);
$html = $this->replacePlaceholder("youtube_id", $youtubeID, $html);
$html = $this->replacePlaceholder("vimeo_id", $vimeoID, $html);
$html = $this->replacePlaceholder("author", $authorName, $html);
$html = $this->replacePlaceholder("numcomments", $numComments, $html);
$html = $this->replacePlaceholder("catlist", $catList, $html);
$html = $this->replacePlaceholder("taglist", $tagList, $html);

我想做的是调用我的自定义帖子类型数据。要在普通模板文件中执行此操作,我可以添加:

get_post_meta( get_the_ID(), 'META_DATA_NAME', true );

我不确定如何将其添加到模板中。我尝试添加下面的代码,但没有任何价值。有人有想法么?谢谢。

$charity = $this->get_post_meta( get_the_ID(), 'META_DATA_NAME', true );

//replace the items in the html
$html = $this->replacePlaceholder("charity", $charity, $html);

【问题讨论】:

  • titlealias 中输入一个奇异的名称,例如StrackOverfrow。搜索数据库。现在你有你的meta_data_name

标签: php wordpress metadata


【解决方案1】:

getValue 函数是否适用于任何帖子元数据或仅适用于 Showbiz 已知的元数据?你试过了吗……

$charity = $this->getValue('META_DATA_NAME');
$html = $this->replacePlaceholder("charity", $charity, $html);

【讨论】:

    猜你喜欢
    • 2020-06-01
    • 1970-01-01
    • 2018-07-22
    • 2011-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-03
    相关资源
    最近更新 更多