WORDPRESS:具有自定义帖子类型+自定义字段的日历 [英] WORDPRESS: Calendar with custom post type + custom fields

查看:107
本文介绍了WORDPRESS:具有自定义帖子类型+自定义字段的日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的情况:
我的客户的wordpress网站有一个事件自定义帖子类型,其自定义字段称为日期(高级自定义字段的日期选择器)。
该网站的所有部分都工作正常,但是现在他们要求我添加一个可获取所有事件的类似小部件的日历。

here's my situation: my client's wordpress site has an "events" custom post type with a custom field called "date" (advanced custom field's datepicker). The site works just fine in all its parts but now they asked me to add a widget-like calendar that fetches all the events.

基本上我需要什么就像get_calendar();但对于使用日期自定义字段而不是创建日期的事件发布类型。
我昨天整天都在寻找插件,hack,代码片段……但似乎没有任何作用。
我知道即使在stackoverflow上也有类似的问题,但仍然没有解决方案...

Basically what i need is something like get_calendar(); but for the "events" post type that uses the "date" custom field instead of the creation date. I spent the whole day yesterday looking for a plugin, hack, snippet of code... but nothing seems to do the job. I know there are similar questions even here on stackoverflow, but still, no solution...

您有任何想法吗?

推荐答案

好,所以您需要的是一个具有自定义查询参数的小部件,该自定义查询args将获取所需的数据。您可以在此处获取有关小部件创建的信息,而ACF文档是此处。自定义查询参数应包括您的自定义帖子类型和所需的ACF数据。例如:

OK, so what you need is a widget that has custom query args that will fetch the data you need. You can get the info on widget creation here, and ACF documentation is here. The custom query args should include your custom post type and the ACF data you need. For example:

<?php 
   $args = array (
     'post_type' => 'events', // your custom post type
     'meta_query' => array(
     'relation' => 'AND', // includes ACF stuff
          array(
          'key' => 'date', // the specific key of your ACF
          'compare' => '='
          )
      )
   );
   $query = new WP_Query($args);
?>

这将从具有日期字段的自定义帖子类型中获取数据库中的所有帖子。您也可以修改值以适合确切的日期。或者通过转发输入指定日期的变量来通过小部件完成操作

This will fetch all the posts from the database from your custom post type that have a date field set. You can modify the value to fit the exact date as well. Or do it through the widget by forwarding a variable for a specific date entered

这篇关于WORDPRESS:具有自定义帖子类型+自定义字段的日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆