Tags create/edit/delete hooks in wordpress - wordpress

I need hooks if tags have removed, created and edited. I have not found them in the WordPress Codex / Function Reference.
For categories:
edit_category
create_category
delete_category
Has anyone encountered this problem?

To explicitly target tags, you'll need create_$taxonomy, edit_$taxonomy and delete_$taxonomy where $taxonomy is post_tag (ie create_post_tag, edit_post_tag and delete_post_tag). They're mentioned in passing in (eg) the wp_insert_term.
Tags are a taxonomy, so the generic actions create_term, edit_term, and delete_term would work as well, though they'll also fire for other taxonomies (such as categories).

You need to use dynamic hooks to taxonomies:
edit_post_tag
create_post_tag
delete_post_tag

Related

Wordpress custom post type in wrong taxonomies

I've add a custom post type with custom taxonomies. I've also added rewrite rules in order to handle following urls:
courses/languages/english/english-course
where courses is the base slug, languages and english are taxonomy slugs and english-course is my custom post. english-course is a child taxonomy of languages and english-course has been categorized in english-course.
My rewrite rule is:
courses/(.+)/(.+)/(.+)/?$ => index.php?thr_course=$matches[3]
Everything works fine but any categories are permitted using this syntax. All following urls are legitimate and work as well:
courses/languages/french/english-course
course/products/english/english-course
course/anycategory/anycategory2/english-course
My rewrite rule is pretty obvious: it only matches my post name ignoring which categories it belongs to.
Where and how should I implement a check in order to return 404
if post exists but parent taxonomies are wrong?
I think WordPrss will not give you a solution for your customization automatically. Fetch other parameters from like parent / child category from URL, similar to thr_course parameter. Use this parameter in your query to narrow down your result.
Hope this will help you.

Page Template for every custom post type

I'm just new in wordpress, I just wanted to ask if it's a bad practice if I'll create page template for every custom post types?
I mean if I have CPT [custom post type] with different content, like my first CPT has images, my 2nd cpt has image and text, my last CPT, has slider, text and description.
Because I wanted to create page template for every type of CPT's I have. Is it a bad practice? Or are there efficient and effective ways to do such things?
Your answers are highly appreciated. Thanks!
It's better not to do that, not only because it's a server load, but also because you'll get crazy if you have an issue. Instead, use conditionals in the same page. You can read about it at WP Codex: Conditional Tags : Taxonomies and then pay attention to the is_tax and has_term tags.
This way, you can use is_tag or has_term depending on your approach, like this
if( has_term( 'jazz', 'genre' ) ) {
// do something
}
You can use taxonomy to deal with such problem. Use taxonomy to filter contents according to your requirements. Use register_taxonomy() to register a taxonomy for CPT.

Wordpress query_posts to modify wp_query

When I alter main $wp_query with query_posts function, all my conditional tags are false and all pages have [is_home] => 1.
So all custom templates I made by modifying main query to save some time are now home. Anyone knows a fix for this?
You should never use query_posts to create custom queries. query_posts breaks the main query, as you have seen. Whether or not to use a custom query for your specific needs, I don't know.
I have done a complete post about this subject on WPSE that you can go and check here. Also go and check out Theme Development in the codex

Is there way to check if a post is attached to a particular taxonomy?

I want to create a condition whereby if a post is attached to a particular taxonomy then some additional code is executed on a modified single.php but I can't find a way to directly check for the taxonomy.
I thought "is_tax" might do the job but it seems that this tag is only effective for archive pages, which I assume means a page that is generated from a template using the taxonomy name.
Is there a direct way to read the taxonomy from a single post so that I can do something similar to:
if (is_tax('chapter')) {additional code}
Thanks
I worked out one solution for this as follows:
$terms = get_the_terms( $post->ID , 'chapter');
if($terms) { *additional code to be added to the template* }
If any terms in the taxonomy 'chapter' are returned the additional code is added to the template otherwise the additional code is omitted.
I don't know if this needs any additional error checking but the code as shown works by including code on the appropriate posts and omitting it where its not required.
Any suggestions on improvements would be welcome.

add custom field template to theme admin page

in WP admin how to add the custom field template plugin to a theme page?
it automatically shows in posts and pages but i want this in the theme page. the theme am using is from iwak "creations" portfolio page.
what files do i need to modify to add this?
It's very hard to say what you need to modify without being able to look at the code. Being a premium theme, we can't just download it and take a look.
Having said that, the theme may use the WordPress custom post type functionality. Search the code for a call to the register_post_type function. If it's used, you may be in luck. Either
add 'custom-fields' to the supports argument in that call, or
call add_post_type_support after the post type is registered. The $post_type parameter will be the first value passed to the register_post_type function, and the $supports parameter will be 'custom-fields'.
Daniel, are you using this Custom Post Type Plugin - http://wordpress.org/extend/plugins/custom-field-template/screenshots/? I've used it before, and the guy who created it is Japanese, so his personal page isn't very useful as far as support for english goes.
I had some trouble with this at first. But what I think you're trying to do is add the custom fields to your new pages you've created, correct?
It's not very straightforward, but once it works it's pretty awesome.
Basically, when you set up the plugin you create these different "Custom fields," right? Well part of that should look like this:
[Custom Field Name]
type = textarea
rows = 4
cols = 40
tinyMCE = true
htmlEditor = true
Ok, so once you've created those "Custom fields" keep note of the part in brackets. You'll add this to your template pages:
<?php getCustomField('Custom Field Name'); ?>
Now when you enter the info in the pages or posts, the content should appear as you've entered it.

Resources