我有一个 Wordpress 站点和一个 Laravel 站点,我想在 Laravel 站点的页脚中显示最近的 wordpress 帖子。如果我的 config/database.php 文件中没有我的 wordpress 数据库信息并在模型中使用它,我该如何做到这一点?我可以使用 RSS 获取它们吗?
我想使用 API 在我的 Wordpress 博客上发帖。因为我在一个 Javascript 应用程序中,所以我会使用这种语言来做到这一点。
我进行了一些搜索,发现使用 Wordpress XML-RPC 协议的node-wpapi包。一切正常,除了发布带有媒体或特色图片的文章。
const responseUploadImage = await wp.media()
.file('./tempImage.jpg')
.create({
title: 'My awesome image',
alt_text: 'an image of something awesome',
caption: 'This is the caption text',
description: 'More explanatory information'
});
const responsePostCreation = await wp.posts().create({
title: 'Your Post Title',
content: 'Your post content',
// status: 'publish'
});
const response = await wp.media().id(responseUploadImage.id).update({
post: responsePostCreation.id
});
Run Code Online (Sandbox Code Playgroud)
它确实创建帖子和上传媒体,但它不会创建带有媒体的帖子。
您知道使用 JS 库创建带有媒体和特色图像的帖子的替代方法或更好的方法吗?
$args = array('numberposts' => 10, 'tag' => 'my-tag', 'ID' => 555');
$posts = get_posts($args);
Run Code Online (Sandbox Code Playgroud)
我只想从特定标签中提取 10 条记录,并且 ID 小于一个数字。有没有办法用 get_posts 参数做到这一点?如何在参数数组中指定大于、小于或不喜欢?
谢谢...
我创建了一个自定义帖子类型 - 按 - 使用functions.php中的以下代码:
// Press Custom Post Type //
function press_custom_init() {
$labels = array(
'name' => _x('Press', 'post type general name'),
'singular_name' => _x('Press', 'post type singular name'),
'add_new' => _x('Add New', 'press'),
'add_new_item' => __('Add New Press Item'),
'edit_item' => __('Edit Item'),
'new_item' => __('New Press Item'),
'view_item' => __('View Press Item'),
'search_items' => __('Search Press'),
'not_found' => __('Nothing found'),
'not_found_in_trash' => __('Nothing found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels, …Run Code Online (Sandbox Code Playgroud) 我有以下数据库,有2列:
posts id category id
1 2
2 1
1 3
3 3
3 2
4 5
Run Code Online (Sandbox Code Playgroud)
我需要一个查询,当提取类别2和3中的所有帖子ID时,这意味着:id为1和3的帖子.
我想通过 id 获取帖子。Id 在数组中。我正在使用这段代码,但现在正在工作。
$the_query = new WP_Query( array(
'post_type' => 'job_listing',
'post__in' => array( 311, 312 )
));
print_r($the_query); //this doesn't print any data
if ( $the_query->have_posts() ) {
echo '<ul>';
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo '<li>' . get_the_title() . '</li>';
}
echo '</ul>';
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试为WordPress创建一个小的搜索功能.AJAX调用应该获得标题所在的所有帖子%quote%.
是否有可能在get_posts()函数内部发生这种情况?
别误会我的意思.ajax运行正常.我的functions.php中有ajax函数,我收到帖子.这只是"我喜欢的地方"部分,我无法找到解决方案.
根据我的理解,wp_postmeta扩展了wp_post的模式.所以基本上,帖子的标准字段/结构将在wp_posts中找到,如果任何帖子需要他们自己的字段/属性集等,它们将在wp_postmeta表中定义.所以我想知道我是否对吗?
谢谢.
我在WordPress上使用静态首页构建了一个自定义主题,并且在"设置">"阅读设置">"首页"中没有设置页面显示为帖子页面.我想根据不同静态页面上整个网站的类别来显示帖子.因此,我永远不会通过控制台声明帖子索引页面.所以我使用$ wp_query函数.
如何在此脚本中添加过滤器,仅显示"apples"类别中的帖子(例如)?现在,此脚本显示所有帖子,无论类别如何.
<?php
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query('showposts=1' . '&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post();
?>
<h2><a href="<?php the_permalink(); ?>" title="Read"><?php the_title(); ?></a></h2>
<?php the_excerpt(); ?>
<?php the_date(); ?>
<?php endwhile; ?>
<?php if ($paged > 1) { ?>
<p><?php previous_posts_link('Previous page'); ?>
<?php next_posts_link('Next page'); ?></p>
<?php } else { ?>
<p><?php next_posts_link('Next page'); ?></p>
<?php } ?>
<?php wp_reset_postdata(); ?>
Run Code Online (Sandbox Code Playgroud) 是否可以“过滤” Wordpress 中页面 ( http://cl.ly/6nLC )的“编辑”屏幕中显示的页面?我已经查看了 Wordpress 插件开发人员的操作/挂钩部分,但找不到任何内容。
我想要完成的是某些用户可以编辑某些页面(和子页面),而其他人无法编辑这些页面,但可能能够编辑其他页面。
我已经写了一个插件,它可以将不同的用户放在不同的组中,现在只需要拥有不同的权限,哪个用户是哪个组的成员存储在 user_meta 表中。
但是,如果有“任何”过滤器挂钩/方法,有人可以指出这一点,我想我可以从那里走得更远。
亲切的问候。