Articles of php

Search.php gets metadata from first post

I’ve got this in header.php in <head> section: $page_color = get_post_meta($post->ID, ‘page_color’, true); It works fine because it gets correct page_color for posts and pages but when I perform some search and search.php is run, it occasionally gets page_color of first post it finds. This is the content of search.php: <?php if( have_posts() ) : […]

populate select options from extra mysql table data

hi guys i am trying to populate a select element with options from the data in one of my sql tables heres what i have so far: <? $SQL = “SELECT * FROM pt_country ORDER BY name”; $rs = $wpdb->query($SQL); $nr = mysql_num_rows($rs); for ($i=0; $i<$nr; $i++) { $r = mysql_fetch_array($rs); echo “<OPTION VALUE=\””.$r[“countrycode”].”\”>”.$r[“country”].”</OPTION>”; } […]

How to decrease the max file upload size without using php.ini or htaccess?

There are a lot of people discussing how to increase the php max upload file size… In my case though I want to shrink it from 8MB to 4MB… In my cpanel configuration, if I change the setting, it will eventually change it for all the websites hosted… which is something I don’t want (on […]

How to get movies by date

Ola, i am building a complex cinema site, and i want to get movies by date Ex: The movies are aded trought post type, I have a custom field name date. How can i retrive the Movie that shoud play today in cinema ( date in custom field : 08.09.2012…) Ex: How can i retrive […]

select wordpress custom post type

I have one wordpress theme which contain Custom Post Type. And in my theme I can add that as a page which show some different URL. Now when I call a WP function (is_page(‘some-page’)) for wordpress page so this code is working. Now for my Custom page I write that same code but it’s not […]

Meta boxes only displayed when editing normal (default wp post_type) posts

I’ve multiple meta boxes for my main/default post types. I also have multiple post_types where this meta boxes make no sense. Can you hint me on if/else function I would use on displaying meta boxes only on default post_type?

include <p> content within conditional statement?

I have a gallery page wherein there are multiple individual galleries/sub-pages. I handle this function by using- <?php if( is_page( 39 ) ) { echo do_shortcode(‘[nggallery id=1]’); } else { } ?> I’m wondering, is there a way to include page specific content in that? For example, if that code is used to show A’s […]

Categories from front-end, checkbox selection doesn't work

I’m using the plugin Post from site, which sets up a WP front end writer. I changed some line of code because I need to select categories with checkboxes and not with a multiple select (as it was originally in the plugin). Unfortunately it doesn’t work: there is a checkbox in the front end writer, […]

Does WordPress cache get_user_meta() results?

If I call get_user_meta() to retrieve a value, does WordPress cache the value? If I call get_user_meta() to retrieve the same value, does WordPress have to query the database again or is it stored in PHP memory?

Check if a class exists within a method

I’m new to OOP and I’m writing my first plugin. I want to check if the Facebook plugin has already been activated. If so, I want to skip some code: class MyClass { … function fb_js_sdk_setup() { // Check if Facebook plugin is activated if ( class_exists( ‘Facebook_WP’ ) ) return; // Continue if Facebook […]