Articles of php

How to display posts of specific category using a custom Query in WordPress?

Hi I want to display a specific category from a custom query in WordPress. My code works fine and it gets the latest 4 posts, but what I want now is to retrieve a specific category. My code is below thanks : global $wpdb; $posts = $wpdb->get_results(‘SELECT ID, post_title AS title, post_excerpt AS excerpt FROM […]

Add WordPress to Meteor js site

I have a Meteor app that I want to add WordPress blogging platform to. There doesn’t need to be any integration, just: http://example.com/blog/ Anything behind blog/ belongs to WP. How would I go about doing this? Thanks in advance.

Memory errors with media upload, WordPress can't use more than 96M (while there's 512 available!)

I’m aware that this is a known problem but I was unable to address it using information found in WPAnswers and WordPress support forums. In my Worpdress single site installation the media uploader is always throwing an error at me out of memory (allocated 99614720) (tried to allocate 3760 bytes) the amount of allocated memory […]

is it possible to force wordpress to always save thumbnails as 'jpg' not 'png'

I cant see any settings and cant see much in the php api docs regarding this? for instance if the original file upload is a png wordpress converts to jpg

using the_permalink to echo an href into a <li>

I’m trying to make a menu that automatically populates from a custom post type I have and I’m having some trouble getting it right If someone could point me in the right direction I would greatly appreciate it. Here is the code. The PHP in the <img src> is pulling the right info and sticking […]

Can is_page() be combined with a switch control structure?

I’m using an if/else control structure to add class attributes to tags. Could I use a switch control structure instead and if so, how? If not, is there a better way to do this than what I’m doing? <div <?php if (is_page( ‘project’ )) { echo ‘class=”project”‘; } elseif (is_page(‘home’)) {echo ‘class=”home”‘; } elseif (is_page(‘contact’)) […]

How to fetch an array in $wpdb?

I have a snippet that will select a data from database table. But I encounter an error: Warning: Invalid argument supplied for foreach() I encounter a new error: Notice: Trying to get property of non-objectin this line echo $result->Name; Snippet (updated): $results = $wpdb->get_results( ‘SELECT DATE_FORMAT(FROM_UNIXTIME(submit_time), “%b %e, %Y %l:%i %p”) AS Submitted, MAX(IF(field_name=”Name”, field_value, […]

Why can't I use “%s” format value in the WordPress function checked?

I try to safe a checkbox with the WordPress settings API. For that I use the checked() function. First I make my field with add_settings_field() and pass a view parameters in an array to the callback function. In the callback function of my field I make an output with printf( ‘<input type=”checkbox” id=”%2$s” name=”%1$s[%2$s]” ‘. […]

Different database query in function.php using mysqli

I am trying to connect to a database in the function.php using mysqli. The code seems to run fine when it is not on a separate php file not on wordpress. But when I run it on wordpress I get “Connect failed: No connection could be made because the target machine actively refused it.” I […]

Using a switch statement in WordPress

I’ve got a piece of text in a div that I want to change on each page of my website. At the moment I’m not sure what function I should be using to do this. Here’s what I have so far… <?php $page = is_page(); switch ($page){ case ‘home’: $content = ‘How much money….’; break; […]