New answers tagged

0

For those who aren't creating a query with get_posts() you may need to reference the global $post variable first before using setup_postdata(). Here is an example shortcode using a foreach loop and iterating through an array of post objects from an ACF Relationship field: function your_shortcode() { //reference global $post first global $post; $...


1

Just a continuation from mozboz' answer. For those curious as I was, you could use the date() or date_i18n() functions to format the date properly in the following snippet. function get_latest_update_date() { global $wpdb; $thelatest = $wpdb->get_var("SELECT max(post_modified) FROM wp_posts WHERE post_type IN ('post', 'page');"); //...


0

$(function($) { $("#btnSubmit").click(function () { //Set the Valid Flag to True if one RadioButton from the Group of RadioButtons is checked. var isValid = $("input[name=gender]").is(":checked"); //Display error message if no RadioButton is checked. $("#spnError")[0]...


5

Background & Core Functionality Why a Taxonomy Path Slug Alone Produces a 404 However this slug doesnt work. mysite.com/wiki/help-topics throws a 404. WordPress does not provide a mechanism for "an archive of taxonomy terms" out of the box - that is, neither the template hierarchy nor the WP_Query/WP_Tax_Query logic support a direct display ...


0

Thanks to @Tunji's answer, I accomplished this with a more generic function: /** * Use output buffering to convert a function that echoes * to a return string instead */ function echo_to_string( $function ) { ob_start(); call_user_func( $function ); $html = ob_get_contents(); ob_end_clean(); return $html; } Then it can be ...


0

Not tested well but you can try this. add_action( 'template_redirect', 'my_homepage_redirect' ); function my_homepage_redirect() { if ( is_home() || is_front_page() ){ $page = get_posts( [ 'post_type' => 'page', 'posts_per_page' => 1, 'orderby' => 'rand', 'fields' => 'ids' ] ); ...


0

I was running into the same issue. Here is what I added to my functions.php to resolve the issue. add_action( 'pre_get_posts', function( $query ) { // When creating custom Rewrites we lose the paged number so we need to set it here. if ( preg_match( '/\/page\/([0-9]+)\/?/', ( ! empty( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( ...


Top 50 recent answers are included