如何在Wordpress中生成顺序编号 [英] How to generate sequential numbering in wordpress

查看:207
本文介绍了如何在Wordpress中生成顺序编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试WordPress的功能,并试图构建一种后台/工作流程系统. 基本原则是,每个帖子都代表一个属于特定类别的职位/规格,等等...到目前为止,它的运行情况很好,但是在生成顺序的职位编号时遇到了麻烦.

I'm testing the capabilities of WordPress and trying to build a kind of back office/workflow system. The basic principle is that each post will represent a job/spec that fall into certain categories etc etc... So far it's working great, but I'm having trouble with generating sequential job numbers.

想法是,当用户发布规格时,WP会自动生成一个唯一的4位ID,该ID代表该规格的工作编号.

The idea is that when the user posts a spec, WP automatically generates a unique 4 digit ID that will represent the job number of that spec.

当前的解决方案仅在每次在不同分类情况下调用帖子时生成id的作用.我想要做的是在发布时生成编号,然后将其永久写入数据库,而不是使用PHP.

The current solution only works as far as generating id's every time a post is called up in different categorised circumstances etc. What I want it to do is generate the number upon posting, then write to the database permanently rather than generate with the PHP.

有人知道我该怎么做吗?

Does anyone have a clue how I can do this?

推荐答案

由于您说无法使用WordPress帖子ID,因此可以创建一个使用 AUTO_INCREMENT 列的表储存它们.在此处插入新条目后,您可以通过PHP检索生成的ID:

Since you said you can't use the WordPress post IDs, you could create a table that uses an AUTO_INCREMENT column to create and store them. After inserting a new entry there, you can retrieve the generated ID via PHP:

$lastid = $wpdb->insert_id;

通过这种方式,您可以让MySQL处理ID的生成并将PHP排除在外.

This way you can let MySQL handle the generation of IDs and leave PHP out of it.

这篇关于如何在Wordpress中生成顺序编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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