I was asked what the advantage or disadvantage in the use of anonymous functions or inline (or onfly), and used a lot in JavaScript, now with 5.3, also in PHP.
An inline function, or anonymous because he did not - in fact - a name, is a quick way to write some procedures, indenting tree sequences such as the callback. Almost all languages support functions of this writing, each to the limit with its peculiarities and restrictions. They may also have different names and syntax details, such as the so-called Objective-C blocks.
Category 'WordPress'
Anonymous functions
WordPress Snippet: extract meta get_posts value with ()
Working with a Custom Post Type ( CPT ) is natural to use the internal functions of WordPress to display and filter the posts of this type. , risulta comodissimo poter creare loop personali sulle proprie tipologie di post. Whether you use the get_posts() is that you create an object directly WP_Query , it is convenient to create loops on their own personal types of posts. WordPress also allows for filters for personal tassionomie, on the count, order, coming up to the meta data. Brand new, in fact, is the process that allows you to specify the conditions where that kind of meta data and compare it with rules.
Bachi beginning of the year: WordPress and WPML get_page_by_path update ()
The year 2012 began with a few hours of deep-debugging because of two (known) bugs quite annoying. , con la globale (e famosa) omonima istanza $wpdb . The first, among other things, rather dated, present in the core of WordPress regarding the method update() class wpdb , with the global (and famous) instance of the same name $wpdb . The defect appears when you try to update a field to NULL . Despite numerous complaints, the WordPress development team does not seem to find a solution to the annoying problem. In fact, to date, the only solution is to write the SQL for your account.
WordPress Snippet: The action save_post
When you add additional fields to the pages and post, or to get Custom Post Type ( CTP ), you have to record an action to save these new data. The implementation of this procedure is essentially always the same, changing only the fields and how to save, the extra data can reside in the 'custom field', ie after half the table, or tables of one or more personal.
WordPress Snippet: is_page () Custom Post Type
If you recorded your own Custom Post Type ( CPT ), especially if you type 'page', you could serve to determine if you are viewing that particular page, the 'single' so to speak. . In this case it is useless to try is_page() or is_page_template() . The clean solution is as follows:
1 2 3 4 5 6 | is_singular ( 'cpt_key' ) ) { if (is_singular ('cpt_key')) { ; global $ post; $post -> post_name == 'slug_pagina' ) { if ($ post -> post_name == 'slug_pagina') { / / Your code here ... type add_action (), wp_enqueue_scripts (), etc ... } } |
WordPress 3.3: now all jQuery
With WordPress 3.3 also jQuery and all its modules have been aligned. Now it is possible to access the new list of the modules of the latest release 3.3, such as the autocomplete. Here is a snippet for a good inclusion:
1 2 3 4 5 6 | / / Load modules that WordPress for us preparatory to the script "MyScript.js" array ( 'jquery-ui-slider' , $ Deps = array ('jquery-ui-slider', 'Jquery-ui-datepicker', 'Jquery-ui-autocomplete' ); , 'js/myscript.js' , $deps , 1 . 3 . 4 , true ) ; wp_enqueue_script ('key', 'js / MyScript.js', $ deps, 1 3.. 4, true); |
WordPress Snippet: add styles and scripts to Custom Post Type
Now that WordPress allows you to create types of custom post (CPT), it becomes useful to be able to add our styles and our script when you view or edit our posts. The best way to do that is compatible with release 3.3 is the following:
1 2 3 4 5 6 7 | , function ( ) { add_action ('admin_enqueue_scripts', function () { ; global $ typenow; $typenow == 'id_custom_post' ) { if ($ typenow == 'id_custom_post') { , 'css/customstyle.css' ) ; wp_enqueue_style ('key_style', 'css / customstyle.css'); , 'js/customscript.js' ) ; wp_enqueue_script ('key_script', 'js / customscript.js'); } }); |
WordPress Snippet: src thumbnail
WordPress allows you to associate a thumbnail to a post , page or post customized. , che restituiscono il completo tag img , risulta meno intuitivo come ottenere il solo link: If it is easy to extract the entire image code, thanks to features the_post_thumbnail() or get_the_post_thumbnail , which return the complete tag img , less intuitive is how to get the single link:
1 2 3 4 | / / If $ post_id is the id of the post get_post_thumbnail_id ( $post_id ) ; $ Image_id = get_post_thumbnail_id ($ post_id); wp_get_attachment_image_src ( $image_id , 'full' ) ; $ Image = wp_get_attachment_image_src ($ image_id, 'full'); [ 0 ] echo $ image [0] |
WordPress Delete Post
WordPress allows you to intercept when a post - even custom type - is being eliminated. . There are two action hooks that can be used: delete_post and deleted_post . In the first analysis, the former should be attributed to a "is being eliminated" the post, even if it does not seem to be, or better.
Very short snippet: set the log files on WordPress
si attivano i log a video prodotti da PHP, riempiendo lo schermo di Notice, Warning e quant'altro. By setting the file wp-config.php define the define('WP_DEBUG', true); logs are activated by PHP-screen products, filling the screen, Notice, Warning, and more. If controls for "flying" this can be useful in situations of exercise is highly recommended, for obvious reasons. Luckily, WordPress allows her to "convey" these logs to a file, which by default is placed in /wp-content/debug.log .






Latest Comments
Robert : I rispsoto your questions with pleasure. The idea is really great. I am looking for a solution ...
Sting : @ Darius - you can see an example here: http://www.fight4fun.it/ clicking on: MAPS I hope ...
vik : Giustappunto I'm working on a project and the client asked me to show all the news (which are CPT) in ...
Giovambattista Fazioli : @ paso: absolutely. Simply identifying the field [cci] input [/ cci] you want to ...
paso : Hello I would like to request a service, you can use the datepicker with cform7 I spiegp best I can implement ...