Welcome Guest, Not a member yet? Register   Sign In
one post in multiple category
#1

hello guys,

wordpress has this feature. please show me simple code and explain for building that. i want submit my post in some categories ( example: IT , personal , food ) and how can edit and remove that post?

thank you so much
Reply
#2

If you are looking to post something in multiple categories on this forum, don't do it ... the moderators will hunt down & delete duplicate posts.

If you are referring to some vaguely specified wordpress feature, then you need to go to the wordpress forum, or else explain what you are trying to do in your CI webapp better.
Reply
#3

i said wordpress for example. just clear sound...
admin, please explain for building that. i can make it too simple: create,edit,delete content/post

but couldn't create,edit,remove my post in some categories.
Reply
#4

I'm sorry - I don't understand what you are asking for help with... using this forum? a program you are writing? a wordpress site you have?
Reply
#5

No that's not wordpress site. i building a simple CMS with codeigniter. and need submiting my post in some categories. how can do it?
Reply
#6

(This post was last modified: 02-14-2015, 11:25 AM by Wouter60.)

WordPress uses three extra tables for that: wp_terms, wp_term_relationships and wp_term_taxonomy.
To keep it simple in CI, just use the tables categories and post_categories.
Categories holds all your categories; where every categorie has a unique ID.
Post_categories holds the post_id and the category_id.

When saving your post, insert the categories into the post_categories table.
User the CI query_builder functions to get all posts that have a specific category.
E.g.:
Code:
$query = $this->db
->select('t1.*')
->select('t3.category_name')
->from('posts t1')
->join('post_categories t2','t1.id = t2.post_id')
->join('categories t3','t2.category_id = t3.id')
->get();
Reply
#7

so how can for update? maybe i want to unselect one category and update my data. could u please update source code?
Reply
#8

The quick and dirty way is to delete all categories that were linked to the post before, and then insert all new or updated categories.
With some more effort you could load the previous set of categories into an array and compare it to the new set of categories. The ones in the old set that don't have a match in the new set, should be deleted. And in the opposite situation, where categories in the new set have no match in the old set, that ones should be inserted.
But the first option is by far the easiest.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB