shorthand syntax for custom fields

You have a couple of flaws in your code get_post_meta( ‘fap_referral_link’ ) should be get_post_meta( $post->ID, ‘fap_referral_link’, true ). Please see get_post_meta() You should always first check if you actually have posts before you run your foreach loop Never ever use extract(). It uses eval() which stand for EVIL. This has been completely removed from … Read more

Ajax resetting my global variable

Each time you’re making an ajax call, $_TEST = 0; is being evaluated again. You use the options API to manipulate your variable. function get_global_val() { $count = get_option( ‘mycount’ ); $count++; //or whatever you want to do with it update_option( ‘mycount’, $count ); die(“New value is $count”); }

Problem in using Customizer

Hey Only Change the code like this function cult_customizer_register( $wp_customize ) { $wp_customize->add_section( ‘cult_topic_thumb’ , array( ‘title’ => __( ‘Topic of the Week’ ), ‘priority’ => 36, ‘description’ => ‘Allows you to upload an image for your topic of the week section.’, ) ); $wp_customize->add_setting( ‘display_topic_thumb’ ); $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, ‘display_topic_thumb’, array( ‘label’ => … Read more

How do I place a function in a standalone page?

If you’re just going to output your own data, there’s no reason to wait for the main query to run. Hook parse_request and check if your page was requested and run your code there. function wpd_maybe_output_feed( $request ){ if( isset( $request->query_vars[‘pagename’] ) && ‘gmailrss’ == $request->query_vars[‘pagename’] ){ header(‘Content-Type:text/xml; charset=UTF-8’); echo checkGmail(“gmail”, “password”); die; } return … Read more

update_post_meta is Updating with two page id

It’s probably Firefox prefetching pages, which it can do based on the rel attribute of links (see https://stackoverflow.com/a/18156967/664741). You could alter these links to remove eg rel=”next”, or you could detect Firefox prefetching by checking the headers sent: if ( ! isset( $_SERVER[‘HTTP_X_MOZ’] ) || $_SERVER[‘HTTP_X_MOZ’] != ‘prefetch’ ) { add_action( ‘wp’, ‘function_name’ ); }

Sort and display pages with specific custom field (not tag)

Thanks @PieterGoosen and @realloc. I came up with this solution: Added meta_key=important&meta_value=1 in wp_list_pages(). And gonna use custom field for pages important: 1. This is for list of IMPORTANT child pages. function important_list_child_pages() { global $post; if ( is_page() && $post->post_parent ) $childpages = wp_list_pages( ‘meta_key=important&meta_value=1&sort_column=menu_order&title_li=&child_of=” . $post->post_parent . “&echo=0’ ); else $childpages = wp_list_pages( … Read more

How to hightlight all ancestor menu items of a child page NOT displayed in menu

You are checking against just one parent item. Instead, you might check against all of the parents <?php //in functions.php add_filter(‘nav_menu_css_class’, ‘highlight_portfolio’, 12, 2); function highlight_portfolio($classes, $item) { $parents = get_post_ancestors(); if ( 0 < count($parents) ) { if ( in_array( $item->object_id, $parents ) { array_push( $classes, ‘current-menu-ancestor’ ); } } return $classes; } Notice … Read more

Modify shortcode to work with custom post types

This part of the code is what defines the arguments that can be passed with the shortcode: extract(shortcode_atts(array( “posts” => ‘8’, “columns” => ‘4’, “category” => ”, “style” => ‘text-normal’, “image_height” => ‘auto’, “show_date” => ‘true’, “excerpt” => ‘true’, ), $atts)); This allows you to later on use this values as $posts, $columns and so … Read more