Show last 5 posts from specific category

Here is the correct way to run this. I am using ‘category_name’ in theme code lately as it is much easier to read and remember. It uses the category slug. Here I am retrieving the last 5 posts in “uncategorized”. function Last5posts() { $args = array( ‘posts_per_page’ => 5, ‘category_name’ => ‘uncategorized’); $last_5_posts_query = new … Read more

Integrating PHP into Javascript to display map markers with Google API

Update 2: <?php $storeData = []; $args = [‘post_type’ => ‘store’]; $loop = new WP_Query($args); foreach ($loop->posts as $post) { $storeData[] = [ ‘title’ => apply_filters(‘the_title’, $post->post_title), ‘lat’ => types_render_field(‘lat’, [‘output’ => ‘raw’]), ‘long’ => types_render_field(‘long’, [‘output’ => ‘raw’]), ]; } wp_localize_script(‘jquery-core’, ‘storeData’, $storeData); ?> <?php get_header(); ?> <!– Row for main content area –> … Read more

How to redirect all 404 in a WordPress subdirectory to the index.php of subdirectory?

You can use a custom endpoint. Just be sure you flush the rewrite rules after it has been added/changed – not every page load! This will turn http://yoursite.com/dev/abc/asdfasdfsdf into http://yoursite.com/dev/abc/index.php?whatever_you_want_your_index_to_see=asdfasdfsdf More Info on rewrite rules: http://code.tutsplus.com/articles/the-rewrite-api-the-basics–wp-25474. After you add a rewrite rule like add_rewrite_rule(‘^dev/abc/([^/]+)/?$’, ‘index.php?’.self::ENDPOINT_SYMBOL.’=1&’ . self::ENDPOINT_PARAM . ‘=$matches[1]’, ‘top’); You can use this great … Read more

Custom Loop Pagination on WordPress

Edit So, the reason that this isn’t working is because you’ve modified the question to specify that this is happening in a custom page template. Since this is the case, you’ll need to use two separate custom queries, and won’t need to bother with filtering the main query via pre_get_posts. The first query will be … Read more

Why does “get_option” pull in the older value in options.php, rather than the newer value, on submission of a form?

If your update_option call runs after you assign $posts1 and $posts2, then of course they’ll hold the “old” value, even if you sleep for eternity 😉 Either run the update earlier, or (re)assign the variables afterwards. $posts1 = get_option( ‘post1’ ); echo get_option( ‘post1’ ); // [my_id] echo $posts1; // [my_id] update_option( ‘post1’, ‘foobar’ ); … Read more

TCPDF get_post_meta outside the loop

I’ve got it fixed: I needed to add the wp-load file that contains all the WP-functions include(‘../../../../../wp-load.php’); global $post; $id = $_GET[‘id’]; $content_post = get_post($id); $content = $content_post->post_content; $content = apply_filters(‘the_content’, $content); $content = str_replace(‘]]>’, ‘]]&gt;’, $content); Now the content loads in the PDF

Changing Link Attributes for Wp_Link_Pages

There is no filter for the URLs, and no filter for the complete output of wp_link_pages(). But you can get the output as string if you pass ‘echo’ => FALSE as argument. There are four options: Write a modified copy of the function with the URLs you need. You will miss all further improvements which … Read more