Blog


Using by reference of WP_Query in posts_search filter hook?

raheelafzal   
No Comments
Sep 18

Problem: User is working on a plugin. He was trying to change the WP_Query fired by the requested page.The query itself is based on several _REQUEST parameters he can use to detect and manipulate because they are unique for his plugin. At first he thought to use the “posts_search” filter hook in his plugin. This hook seemed good as it is passing the WP_Query object by reference. He managed to determine and change the WP_Query object to reflect the new query parameters for his purpose. Unfortunately, this approach didn’t work because the changed WP_Query object was not used for the

WordPress TinyMCE : Wrap several elements in DIV

raheelafzal   
1 Comment
Sep 17

Problem: User wants to know if it is possible to wrap multiple items in a div by using TinyMCE? He wants to avoid using a shortcode. Here is a setup: $style_formats = array( array( ‘title’ => ‘Title with list’, ‘block’ => ‘div’, ‘classes’ => ‘my-class’, ‘wrapper’ => true, ), ); The result: Title Some text… Some text… Some text… But he wants to has something like this: Title Some text… Some text… Some text… Solution 1: I think you have to use a different method to do this. Based on the documentation here: https://www.tinymce.com/docs/configure/content-formatting/#formats Take a look here: https://codex.wordpress.org/TinyMCE_Custom_Buttons And

What does “object_id” means?

Asif   
No Comments
Sep 16

Problem: User wants to know about object id. He read database description- http://codex.wordpress.org/Database_Description#Table:_wp_terms, and get the table description: Table: wp_term_relationships Field Type Null Key Default Extra object_id bigint(20) PRI Pt1 0 term_taxonomy_id bigint(20) PRI Pt2, IND 0 He know term_taxonomy_id is FK->wp_term_taxonomy.term_taxonomy_id, but how about object_id? He has a further question:where are “object_id” from? He checked the table “wp_posts” and “wp_links” and found no fields relative to “object_id”. Solution 1: A quote from: http://boren.nu/ “object_id” is the ID of a post or link. “term_taxonomy_id” is an ID from the term_taxonomy table designating a particular term+taxonomy pair. Solution 2: In wp_posts,

if logged in?

Asif   
No Comments
Sep 15

Problem: Problem is to design login page with your own requirements. How do you create a page so if you are logged in it says Welcome “user” on the pages instead of just the static or builtin “Login” page. Solution: You’d need to know some PHP. Here’s how to access the username: http://codex.wordpress.org/Function_Reference/get_userdata Conclusion: Designing your website in a proper way is very important. So above codex will help you to design your login page in your desired layout

Only show posts if they’re less than 3 days old

Asif   
No Comments
Sep 12

Problem: User would like to add a “breaking news” just under the header on site’s custom front page. He wants to show only those posts that are less than 3 days old from a specific category. His opinion is to put the entire mini-loop inside a php if statement then compare the post date to a number and only print the breaking news ticker if it is less than that number. If there aren’t any breaking news posts in three days, the ticker doesn’t show up any thing. Users mini-loop working beautifully, posting the 6 most recent news posts on

Fetching post content from all top-level terms in a custom taxonomy

Asif   
No Comments
Sep 11

Problem: User has been trying to figure this out for a while, searching the internet for solutions but not helpful. User has created a custom post type products, with a custom taxonomy of product_type. What He is trying to do is create a query that will fetch all top level posts (in alphabetical order) in the product_type taxonomy and output the first n number of posts related to each taxonomy term. Example: product_type A – Post 1 – Post 2 product_type B – Post 1 – Post 2 product_type C – Post 1 – Post 2 He has been playing

Retrieve category_id’s in the loop

raheelafzal   
No Comments
Sep 10

Problem: User is looking for the right function to retrieve all category_id’s of a specific post within the loop. He wants to store the id’s in a variable or an array. Following is the solution of above stated problem. Solution: We have finally found the function to solve the problem. foreach((get_the_category()) as $cat) { echo $cat->cat_ID; } Conclusion: Its solution is very simple. You have to just use above code in your website and enjoy the results.

New error notice for WP_Post::$ancestors in 3.5

Asif   
No Comments
Sep 09

Problem: This problem is with the newest version of WordPress. User has used this function without problems in the past, but in 3.5. He has received an error notice, which reads: Notice: Indirect modification of overloaded property WP_Post::$ancestors has no effect in /mysite.com/public_html/wp-content/themes/mytheme/functions.php on line 09 Line 9 is: return end($post->ancestors); function get_top_parent_page_id() { global $post; // Check if page is a child page (any level) if ($post->ancestors) { // Grab the ID of top-level page from the tree return end($post->ancestors); } else { // Page is the top level, so use it’s own id return $post->ID; } } The

wp-login.php blank page

Asif   
No Comments
Sep 07

Problem: In this problem user won’t be able to logged in to his WordPress website account. He has a problem regarding logging on his website that runs on WordPress. He upgraded WordPress to 3.3.1. Everything worked fine till this morning but now he couldn’t login anymore on WordPress, and he just got a blank page. The username and password are totally correct. He has deleted all the plugins from wp-content/plugins folder to see if there is a problem with them and made the upgrade again but no results found. He has installed the older version of WordPress, again, and still

Page 1 of 212

About Code Movement


Code Movement is all about spreading awareness about coding and its scope. Our agenda is to unleash true potential of programming in Pakistan by leveraging skills of our schools & college students, university under grads & industry professionals and helping the next generation to excel in the world of Software Development.

Come. Learn. Serve.

Let's Get In Touch!

Got any questions? No problem! Give us a call or send us an email and we will get back to you as soon as possible!

Top