Nokaa
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Hook save_post on multiple posts edit (bulk action)Yes it can be an ongoing script. The bulk actions is a precaution for the future but I don’t think that we’ll need it later.
This seems to be very pernickety to launch a ongoing script on WordPress. I don’t really know how to process without any hook… I tried it by creating a plugin that calls a function without conditions (on activation), it result in a blank page. My entiere WP was broken until I take off my plugin on the FTP.
Forum: Developing with WordPress
In reply to: Hook save_post on multiple posts edit (bulk action)This is a great alternative.
However, I got another problem with that : when I try to apply my function, it seems to work because I can see what is added in my custom field when I edit a post (single). However, if I don’t update manually this post after that, it seems to not be registered in the database (only in a kind of cache ?). I tried to force update with the function wp_update_post(), but it doesn’t work :
Here’s my part of code :
/* Custom bulk action (multiple posts) */ // register add_filter( 'bulk_actions-edit-post', 'register_add_auto_forms' ); function register_add_auto_forms($bulk_actions) { $bulk_actions['add_auto_forms'] = __( 'Ajouter les formulaires', 'add_auto_forms'); return $bulk_actions; } // handler add_filter( 'handle_bulk_actions-edit-post', 'add_auto_forms_handler', 10, 3 ); function add_auto_forms_handler( $redirect_to, $doaction, $post_ids ) { if ( $doaction !== 'add_auto_forms' ) { return $redirect_to; } foreach ( $post_ids as $post_id ) { $all_terms = get_the_terms( $post_id, 'cm'); if ($all_terms[0]->name != null){ $cm = $all_terms[0]->name; $shortcode = form_filter($cm); $city_select = '[WG_zip2City zipcodeFieldId="cp" cityFieldId="ville"]'; $shortcodes = ''.$shortcode.$city_select; update_field('formulaire', $shortcodes, $post_id); $post_args = array('ID' => $post_id,); wp_update_post($post_args); } } $redirect_to = add_query_arg( 'bulk_add_auto_forms_posts', count( $post_ids ), $redirect_to ); return $redirect_to; }$shortcode is declared higher.
Sorry for the thread… I finally found the answer in the docs : http://docs.kingcomposer.com/set-template-path/
I had not looked for the good terms.For those who are wondering how to make it work, just add this to your child theme function.php :
add_action('init', 'kc_init', 99 ); function kc_init(){ global $kc; $kc->set_template_path( get_stylesheet_directory().'/kingcomposer/' ); }Now it will take the templates of the plugin, those of the parent theme, and also those which are located in the kingcomposer/ folder of your child theme.
Sincerely yours,
N.C.
Forum: Fixing WordPress
In reply to: change background at specific GIF frameThere is no way IMO to manage events depending on a current GIF frame.
I advise you to convert your gif frames as a static spritesheet and to take a look at the canvas tag : http://www.williammalone.com/articles/create-html5-canvas-javascript-sprite-animation/
Which is anyway the best and proper way to do what you want (and more).Forum: Developing with WordPress
In reply to: Force post-type to keep only post-name in permalinkIn summary, there are four things to coordinate so this scheme works. Output the correct permalink depending on post type. Ensure there are no duplicate slugs among all post types. Add a rewrite rule that recognizes the request, but does not interfere with other similar unrelated requests. Adjust the post_type query var in “pre_get_posts” to account for any possible post type.
So, you mean somethink like that ?
add_filter('post_type_link', 'change_permalink_structure', 10, 4); function change_permalink_structure($post_link, $post, $leavename, $sample) { if ( 'formulaire' == get_post_type() ) { $category_terms = get_the_terms( $post->ID, 'category' ); if(!is_wp_error($category_terms)) $term = $category_terms[0]->slug; $post_link = str_replace( '/' . $post->post_type . '/', '/' . $term . '/', $post_link ); } elseif ( 'metier-ville' == get_post_type() ) { $category_terms = get_the_terms( $post->ID, 'category' ); if(!is_wp_error($category_terms)) $term = $category_terms[0]->slug; $post_link = str_replace( '/' . $post->post_type . '/', '/' . $term . '/', $post_link ); } elseif ( 'metier-artisans' == get_post_type() ) { $category_terms = get_the_terms( $post->ID, 'category' ); if(!is_wp_error($category_terms)) $term = $category_terms[0]->slug; $post_link = str_replace( '/' . $post->post_type . '/', '/' . $term . '/', $post_link ); } return $post_link; } function na_parse_request( $query ) { if ( ! $query->is_main_query() || 2 != count( $query->query ) || ! isset( $query->query['page'] ) ) { return; } if ( ! empty( $query->query['name'] ) ) { $query->set( 'post_type', array( 'post', 'formulaire', 'metier-ville', 'metier-artisans', 'page' ) ); } } add_action( 'pre_get_posts', 'na_parse_request' );The permalink is well set in the back-office when you edit the post, however when we try to display it, it first display the right custom permalink on the web browser (“domain/category/post_name”) and while the page is loading suddenly “poof”, it transform the category into the post_type again (“domain/post_type/post_name”). I don’t understand this behaviour. I tried to change the priority of execution but didn’t work.
Forum: Developing with WordPress
In reply to: Force post-type to keep only post-name in permalinkNot resolved.
Seems to work for only one CPT.
Doesn’t know how to make the filter work for all CPT…
EDIT : And seems to break some others links like “pages” which return a 404 Error… I’m lost.- This reply was modified 8 years, 11 months ago by Nokaa.
Forum: Developing with WordPress
In reply to: Force post-type to keep only post-name in permalinkI think it’s resolved, finally did it by creating a kind of filter that change my permalink structure writed directly in the register function.
Here’s an example :register_post_type( 'artisan', array( 'labels' => array( 'name' => 'Artisans', 'singular_name' => 'Artisan', 'menu_name' => _x( 'Artisans', 'taxonomy general name'), ), 'description' => 'List of artisans', 'public' => true, 'menu_position' => 5, 'menu_icon' => plugins_url( 'icons/icon_artisan.svg', __FILE__ ), 'supports' => array( 'title', 'editor', 'custom-fields' ), 'taxonomies' => array( 'category' ), 'rewrite' => array( 'slug' => '/%category%', 'with_front' => false, ), )); /* Change permalink structure */ add_filter('post_type_link', 'events_permalink_structure', 10, 4); function events_permalink_structure($post_link, $post, $leavename, $sample) { if ( false !== strpos( $post_link, '%category%' ) ) { $category_term = get_the_terms( $post->ID, 'category' ); $post_link = str_replace( '%category%', array_pop( $category_term )->slug, $post_link ); } return $post_link; }Note: Works also with custom taxonomies, by remplacing %category% and ‘category’ by the custom taxonomies slug.
I thought that modify directly the $post_link variable should bring some mess, but finally seems to be the good way.
Forum: Developing with WordPress
In reply to: Force post-type to keep only post-name in permalinkThank you for your help.
Finally my manager wanted to display the category instead of the post-type in the link.
So I managed to do something like that :function na_remove_slug( $post_link, $post, $leavename ) { if ( 'formulaire' != $post->post_type || 'publish' != $post->post_status ) { return $post_link; } $category = get_the_terms( $post->ID, 'category'); if (!is_wp_error( $category)) $post_link = str_replace( '/' . $post->post_type . '/', '/' . $category[0]->slug . '/', $post_link ); else $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link ); return $post_link; } add_filter( 'post_type_link', 'na_remove_slug', 10, 3 ); function na_parse_request( $query ) { if ( ! $query->is_main_query() || 2 != count( $query->query ) || ! isset( $query->query['page'] ) ) { return; } if ( ! empty( $query->query['name'] ) ) { $query->set( 'post_type', array( 'post', 'formulaire', 'page' ) ); } } add_action( 'pre_get_posts', 'na_parse_request' );The pemalink is well displayed in the UI :

However even if I refresh the permalink, I got an error 404 when I try to display the post.
What did I wrong ?
Forum: Developing with WordPress
In reply to: Force post-type to keep only post-name in permalinkI think it’s already what I did with the functions I found in the first link of my post.
But what will be fine is the possibility to apply my permalink setting (in Settings -> permalink) to the CPT too. What I need (using only %post_name%) works on default posts, but not on my CPT.
Permalink settings :

Work on default posts :

Don’t work on CPT (still keep the post type prefix) :

Is there a way to make my CPT use the permalink settings ?
Forum: Plugins
In reply to: [Contact Form 7] Custom id in shortcode ?Oops, can’t edit.
I created a little plugin with tons of cases in a switch that connect CF ids with my terms, it was longer but my problem is resolved.Forum: Plugins
In reply to: [Contact Form 7] Custom id in shortcode ?Hm… No it can’t really help. :/
I think the only way I can do what I need is by being able to change the “id” of a form (the back-end id, not the front-end id). Actually they’re generated automatically when saving a new form, and there’s no way to change them.
Thank you anyway.
- This reply was modified 8 years, 11 months ago by Nokaa.
Forum: Plugins
In reply to: [Contact Form 7] Checkbox automatically add tags ‘[]’ after its nameDidn’t know that…
So I presume I need to use them whatever happen if I want to send multiple values for my checkbox groups.Thank you for your fast answer
Forum: Plugins
In reply to: [Contact Form 7] Checkbox automatically add tags ‘[]’ after its nameFor now and if someone asks for a solution, I rectified that behaviour with a little function :
// Rectify checkboxes "name" generated from Contact Form 7 function rectifyCheckboxInput(){ var checkbox = $('.wpcf7-form').find('input[type=checkbox]'); $.each(checkbox, function(i, el){ current_name = $(el).attr('name'); $(el).attr('name', current_name.replace('[]','')); }); } rectifyCheckboxInput();But I still think that thoses additionnal tags are undesired … Maybe an error in the plugin ? Or is there another reason ?
- This reply was modified 9 years ago by Nokaa.
Forum: Fixing WordPress
In reply to: Post not visible on frontendYes, simply don’t create a template for it.
However a default frontpage will still exist for the custom-post (the single.php template), I think that you can remove the access of it by setting the ‘publicly_queryable’ parameter to false in the register function : https://codex.wordpress.org/Function_Reference/register_post_type#public
Forum: Developing with WordPress
In reply to: Can’t find a way to load my script after Google Maps APIOh my bad, seems that my answer was not well sended yesterday.
What data do you need to localize that is needed from the query? […] Is this the main query for the page or a custom query on the template?
In fact, in the middle of my template, I call a wp_query which return a list of profils (a custom post-type) which are associated with the region or the postal codes of the current custom post-type. So the result of the wp_query totally depend on the current post, so it need to be called in the template.
Thoses profils have custom fields that I need to create the markers on my map (like the address and the city which enable me to get the location with the google geocoder, the name, the forname, the mark, etc.). I’ve my own script to do that, so it need to be loaded after the googlemap API script. And I need to localize thoses data in my own script.