Is it possible to isolate and use WordPress functions outside of wordpress

One way to access WordPress core functionality outside of your WordPress directory is to use the following example; <?php require( ‘../path-to-your-wordpress-install/wp-load.php’ ); get_header(); // do your magic here… get_footer(); ?> However converting HTML to WordPress shouldn’t really require you to access WordPress outside of itself. Instead you want to be porting across the clients HTML … Read more

Settings options not showing up on Sub Menu page in WordPress plugin

If you check the arguments for add_menu_page, you’ll see that the fifth argument is your callback function. And, right now, there’s nothing in the mj_admin function. What you need to do is output your form in that function. <?php function mj_admin(){ ?> <h2>My Settings Page</h2> <form action=”options.php” method=”post”> <?php settings_fields( ‘mj-admin-settings’ ); do_settings_sections(‘mj-admin-settings’); submit_button(); ?> … Read more

Change Query Arguments (filter) with jQuery/Ajax or PHP?

The permalink structure you’ve described above e.g…./hotels/hamburg/features/sea-face isn’t really something that could be achieved by using custom fields. You would be better off creating a new taxonomy called ‘features’ and populating it with terms like ‘sea-facing’ and any others. In order to do queries for multiple taxonomies I would recommend the excellent Query Multiple Taxonomies … Read more

Need help with simple “if statement” checks to output particlular CPT data depending on what client uploads/fills out

You’ve got some basic syntax problems. Your elseif statement wasn’t actually checking anything and wasn’t properly wrapped in parenthesis. The logic more appropriately checks if the first condition is true, then if the second condition is true, and finally if all else fails, display the hard coded image. <?php $meta_box_topbanner_url = get_post_meta( $post->ID, ‘meta_box_topbanner_url’, true … Read more

Fetching review value using wpdb class

You need to add the global $wpdb reference and also add the second parameter required for prepare(): global $wpdb; $post_id = $post->ID; $reviewScore = $wpdb->query( $wpdb->prepare( “SELECT review FROM {$wpdb->prefix}gdsr_data_article WHERE post_id = %d”, $post_id ) );

WordPress Post HTML after Posting

add_action(‘publish_post’, ’email_post’); function email_post($postID) { $post = get_post($postID); $content = $post->post_content; $content = apply_filters(‘the_content’, $content); $content = str_replace(‘]]>’, ‘]]>’, $content); $mailto = ‘youremail’; $subject=”New Post”; if(mail($mailto, $subject, $content)) return true; else return false; } Be sure to set your headers or anything else you might need to populate your email correctly. This is untested, but … Read more

How to randomise my menu items?

Ehm, afaik the return value of the menu fn is an object: You need to type cast earlier $menu_items = (array) wp_get_nav_menu_items( 26 ); // Typecast here $menu_items = array_rand( $menu_items, 3 ); foreach ( $menu_items as $key => $menu_item ) { echo $menu_item[‘title’]; }

Insert PHP code in Text

A better, cleaner way to do this would be to use proper string return methods and concatenation. I say this, because you’re trying to put functions that echo content (i.e. the_title() into a variable – this won’t work!!! Instead: $text=”<form><td>Permalink to: “; $text .= get_the_title(); $text .='</td><textarea cols=”85″ rows=”2″ readonly=”readonly” onclick=”select()”/>’; $text .= get_permalink( $id … Read more