Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create posts with tag and cover image #410

Open
mafiadek opened this issue Aug 15, 2018 · 4 comments
Open

Create posts with tag and cover image #410

mafiadek opened this issue Aug 15, 2018 · 4 comments

Comments

@mafiadek
Copy link

  • Corcel Version: v.2.6.3
  • Framework Name & Version:
  • PHP Version:
  • Database Driver & Version:

Description:

how to create new post with tag and category and set cover image

Steps To Reproduce:

@namnguyen2091
Copy link

namnguyen2091 commented Nov 7, 2018

I have the same question. I dont know how to insert new post with Corcel, I want to use posts table with other purpose. I think this is a new function in a future, I can not find this in code.

@jgrossi
Copy link
Member

jgrossi commented Nov 13, 2018

@mafiadek @namnguyen2091 thanks for sharing! actually, Corcel works on the top of Laravel's Eloquent ORM, so you can use all the relations the Post class has and insert what you want.

it should work fine when inserting, I cannot see any other restriction, but if so just let me know here and we try to fix that asap. basically you are going to use the $post->taxonomies() relation:

$post = Post::create([/* args */);
$post->taxonomies()->create(/* args */);

WP database uses 4 tables to do that, so you should touch all the necessary relations. you're going to use wp_posts, wp_term_relationships, wp_term_taxonomy and wp_terms.

it would be nice to have something like $post->addTerm($taxonomy, $term). you're also welcome to send a PR with this addition. a start point could be the $post->hasTerm($taxonomy, $term) method. take a look deeper how it works and it would be easier to do the opposite - inserting instead of querying.

let me know any other thoughts! you're welcome! 😎💪🎉

@jgrossi
Copy link
Member

jgrossi commented Nov 13, 2018

@mafiadek @namnguyen2091 just created a addTerm() method to the Post class. let me know your thoughts. Here is the PR #425. thanks! 🎉💪

@namnguyen2091
Copy link

I see. Thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants