我有一个主题,非常适合我需要的东西。我只需要更多的功能。我会说我作为程序员对wordpress有点新,但确实有一些以前的PHP经验。当项目帖子完成时,我需要以某种方式从项目帖子中自动生成帖子。通常,当它完成时,它将有一个达到100的条,变成绿色并说成功。当这种情况发生并且结束日期已经过去时,我需要启动一个新帖子,其中已经内置了某些数据(只提供访问权限的用户ID等),以便创建的内容有某处可去被观看。如果我不能做这样的事情,它可能会在将来给我带来可怕的过多手工作品。我试图将它插入div中,当打破页面时,我尝试在functions.php中尝试这样做,以为我可能会错过某些特定于wordpress的操作顺序。这是我试图使用的代码:
<?php
function newvid_create_post() {
$post_id = -1;
// Setup the author, slug, and title for the post
$author_id = 1;
$slug = 'postingtest';
$title = 'MySite Library Test';
// If the page doesn't already exist, then create it
if( null == get_page_by_title( $title ) ) {
// Set the post ID
$post_id = wp_insert_post(
array(
'comment_status' => 'closed',
'ping_status' => 'closed',
'post_author' => $author_id,
'post_name' => $post_id,
'post_title' => $title,
'post_status' => 'publish',
'post_type' => 'post'
)
);
// Otherwise, it'll stop
} else {
// Using -2 to indicate that the page with the title already exists
$post_id = -2;
} // end if
} // newvid_create_post
add_filter( 'after_setup_theme', 'newvid_create_post' );
The various calls to this function would look like this:
$post_id = newvid_create_post()
if( -1 == $post_id || -2 == $post_id ) {
}
?>
</div>
我也试过这样的事情,但不确定如何自动将数据库变量集成到帖子中。
function show_post_type(){
$labels = array(
'name' => 'Show',
'singular_name' => 'Show',
'add_new' => 'Add Show',
'all_items' => 'All Shows',
'add_new_item' => 'Add Show',
'edit_item' => 'Edit Show',
'new_item' => 'New Show',
'view_item' => 'View Show',
'search_item' => 'Search Show',
'not_found' => 'No Shows Found',
'not_found_in_trash' => 'No Shows Found in Trash',
'parent_item_colon' => 'Parent Reward',
);
$args = array(
'labels' => '$labels',
'public' => true,
'has_archive' => true,
'publicly_queryable' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'support' => array(
'title',
'editor',
'excerpt',
'thumbnail',
'revisions',
),
'taxonomies' => array('category', 'post_tag',),
'menu_position' => 6,
'exclude_from_search' => false,
);
register_post_type('show', $args);
}
对于那些页面上的验证,例如:
<?php $user_ID = get_current_user_id();
$query = "SELECT * FROM wp_posts WHERE '$user_ID'='$post_author' AND post_type='project' OR post_type='funder';
$result=mysqli->query($query);
$count=mysqli->_num_rows($result);
if(count==1){
echo "Access Granted." // I want to put access to the actual media here
}
else{
echo "No Access" // I am looking to put the redirect to the payment page for access here which // will insert them into the table as a "funder".
}
?>
我使用的表是针对上面查询中看到的自定义帖子类型设置的。我必须确保它们与上面看到的post_parent或他们的兄弟姐妹相匹配,以便只有为项目做出或贡献的人员才能查看页面/帖子,并且只允许一个帖子分配具有特定权限的新用户角色当每个人每次加入时插入每个帖子会非常痛苦。出于某种原因,我认为我可能会把事情放在错误的区域/格式但不能确定,我现在已经尝试了一个半月。如果有人有任何想法或者能指出我正确的方向,我将非常感激。