Wordpress选项表保存条目子集时删除所有值

时间:2016-05-18 02:09:31

标签: php wordpress

我有一个使用Wordpress选项的插件 - 它会保存每个页面的数据,并使用ID标记发布,我可以在前端拉出并显示该帖子或页面的自定义数据。

例如,我可以为每个帖子1-25输入自定义数据,成功保存到Options.php,转到第2页,我看到帖子条目26-50,并保存这些条目的数据......但是保存26-50的数据擦除了我刚刚保存在条目1-25和51- x

上的数据

我正在使用的分页代码是一个自定义代码段:

$how_many_results = 25;
$post_args = array('numberposts' => -1, 'posts_per_page' => $how_many_results, 'orderby' => 'title', 'order' => 'ASC', 'paged' => $paged,'post_type' => 'post')
$posts_query = new WP_Query( $post_args );
$mnposts = $posts_query->max_num_pages;
$big = 999999999999;
$posts_pagination = paginate_links(array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'current' => max( 1, $paged ),
'total' => $mnposts,
'end_size' => 1,
'mid_size' => 1,
'prev_next' => True,
'prev_text' => __('Prev','cust_dataset'),
'next_text' => __('Next','cust_dataset'),
'type' => 'list'
));
echo (!isset($posts_pagination))?'<span>'.__('All posts displayed','cust_dataset').'</span>':$posts_pagination;

这是HTML格式:

<form method="post" action="options.php">
<?php
settings_fields('cust_options_post');
$cust_posts = get_option('cust_settings_post');
$cust_name = 'cust_name_'.get_the_ID();
$cust_name_set = (isset($cust_posts[$cust_name]))?$cust_posts[$cust_name]:'';
$option .= '<input type="hidden" name="cust_settings_post['.get_permalink().']" id="cust_settings_post['.get_permalink().']" value="'.$red_url.'" />';
$option .= '<strong>' . get_the_title() . '</strong> (<em><a href="' . get_admin_url() . 'post.php?post=' . get_the_ID() . '&action=edit">edit</a></em>)';
$option .= '<br />' . get_permalink() . ' (<em><a href="' . get_permalink() . '">view</a></em>)';
$option .= '<input type="text" name="cust_settings_post['.$cust_name.']" id="cust_settings_post['.$cust_name.']" value="'.$cust_name_set.'" />';
?>
<?php echo $option; ?>
<input type="submit" />
</form>

问题在于,Pagination一次只拉25个,而Wordpress在每个表单提交上重新保存整个Options块,即使它只是25个条目的子集。如果我有100页,这不会是一个问题,但我在一个有超过30,000个帖子的网站上运行它......我不能让服务器一次性处理30,000个选项数据集。

我的问题是:如何将一个数据子集保存到Options.php而不删除我之前保存的当前子集中的剩余数据?< /强>

1 个答案:

答案 0 :(得分:0)

所以,经过一些研究,我会回答那些可能会跟随的人的问题。

设置字段作为单个数据库表条目存储在Wordpress选项表中。因此,当您修改并保存信息位,或者在这种情况下是该信息的子集时,Wordpress会重写该设置字段的整个表条目,因此每次保存时它都会覆盖它。

在该条目中保存其余数据的唯一方法是将其拉出并将其存储在变量中,然后在重新保存之前将其附加到修改后的代码中。但是,问题在于,当您开始处理大量数据时。在我的情况下,我为30,000个帖子中的每一个保存了额外的数据位,这是用尽服务器上的所有内存来尝试处理这些页面的数据的好方法......即使你在&#39;仅查看25或50个条目的子集。

你去。