Tutorial by Examples: e

Let's say we want to change main loop, only for specific taxonomy, or post type. Targeting only main loop on book post type archive page. add_action( 'pre_get_posts', 'my_callback_function' ); function my_callback_function( $query ) { if( !$query->is_main_query() || is_admin() ) return;...
add_action( 'pre_get_posts', 'single_category' ); function single_category( $query ) { if( !$query->is_main_query() || is_admin() ) return; $query->set( 'cat', '1' ); return; }
Sometimes you would like to change main WordPress query. Filter pre_get_posts is the way to go. For example using pre_get_posts you can tell main loop to show only 5 posts. Or to show posts only from one category, or excluding any category etc. add_action( 'pre_get_posts', 'my_callback_function' ...
add_action( 'pre_get_posts', 'single_category_exclude' ); function single_category_exclude( $query ) { if( !$query->is_main_query() || is_admin() ) return; $query->set( 'cat', '-1' ); return; }
All we need to do is to use set() method of $query object. It takes two arguments, first what we want to set and second what value to set. add_action( 'pre_get_posts', 'change_posts_per_page' ); function change_posts_per_page( $query ) { if( !$query->is_main_query() || is_admin() ) retu...
Let's say you need to check if an email address appears in a long list of email addresses. Use the MATCH function to return the row number on which the email address can be found. If there is no match, the function returns an #N/A error. =MATCH(F2,$D$2:$D$200,0) The value you're retrieving ...
DECLARE @xmlIN XML = '<TableData> <aaa Main="First"> <row name="a" value="1" /> <row name="b" value="2" /> <row name="c" value="3" /> </aaa> <aaa Main="Second"> &l...
Singletons in Java are very similar to C#, being as both languages are object orientated. Below is an example of a singleton class, where only one version of the object can be alive during the program's lifetime (Assuming the program works on one thread) public class SingletonExample { priva...
Continuing on the mtcars example, here is a simple way to produce a plot of your linear regression that is potentially suitable for publication. First fit the linear model and fit <- lm(mpg ~ wt, data = mtcars) Then plot the two variables of interest and add the regression line within the d...
The Math.max() function returns the largest of zero or more numbers. Math.max(4, 12); // 12 Math.max(-1, -15); // -1 The Math.min() function returns the smallest of zero or more numbers. Math.min(4, 12); // 4 Math.min(-1, -15); // -15 Getting maximum and minimum from an array: var ...
Java SE 7 switch itself can not be parameterised to be case insensitive, but if absolutely required, can behave insensitive to the input string by using toLowerCase() or toUpperCase: switch (myString.toLowerCase()) { case "case1" : ... break; case &...
As-per the Haskell 2010 Language Specification, the following are standard IO functions available in Prelude, so no imports are required to use them. getChar :: IO Char - read a Char from stdin -- MyChar.hs main = do myChar <- getChar print myChar -- In your shell runhaskell MyChar...
Encoding //convert the image to NSData first let imageData:NSData = UIImagePNGRepresentation(image)! // convert the NSData to base64 encoding let strBase64:String = imageData.base64EncodedStringWithOptions(.Encoding64CharacterLineLength) Decoding let dataDecoded:NSData = NSData(base64Encoded...
ENUM provides a way to provide an attribute for a row. Attributes with a small number of non-numeric options work best. Examples: reply ENUM('yes', 'no') gender ENUM('male', 'female', 'other', 'decline-to-state') The values are strings: INSERT ... VALUES ('yes', 'female') SELECT ... --> ...
Let's say we have type ENUM('fish','mammal','bird') An alternative is type TINYINT UNSIGNED plus CREATE TABLE AnimalTypes ( type TINYINT UNSIGNED NOT NULL AUTO_INCREMENT, name VARCHAR(20) NOT NULL COMMENT "('fish','mammal','bird')", PRIMARY KEY(type), INDEX(na...
Let's say we have type ENUM('fish','mammal','bird') An alternative is type VARCHAR(20) COMENT "fish, bird, etc" This is quite open-ended in that new types are trivially added. Comparison, and whether better or worse than ENUM: (same) INSERT: simply provide the string (worse?)...
ALTER TABLE tbl MODIFY COLUMN type ENUM('fish','mammal','bird','insect'); Notes As with all cases of MODIFY COLUMN, you must include NOT NULL, and any other qualifiers that originally existed, else they will be lost. If you add to the end of the list and the list is under 256 items, the ALTER...
Haskell supports many forms of concurrency and the most obvious being forking a thread using forkIO. The function forkIO :: IO () -> IO ThreadId takes an IO action and returns its ThreadId, meanwhile the action will be run in the background. We can demonstrate this quite succinctly using ghci: ...
Changing an auto-increment value is useful when you don't want a gap in an AUTO_INCREMENT column after a massive deletion. For example, you got a lot of unwanted (advertisement) rows posted in your table, you deleted them, and you want to fix the gap in auto-increment values. Assume the MAX value o...
To insert data retrieved from SQL query (single or multiple rows) INSERT INTO Table_name (FirstName, LastName, Position) SELECT FirstName, LastName, 'student' FROM Another_table_name Note, 'student' in SELECT is a string constant that will be inserted in each row. If required, you can select a...

Page 527 of 1191