How to get 2 or multiple custom post types in wordpress functions.php

In your if statement just add more conditions like this. function et_last_modified_date_blog( $the_date ) { if ( ‘post’ === get_post_type() || ‘movies’ === get_post_type() || ‘etc’ === get_post_type()) { $the_time = get_post_time( ‘His’ ); $the_modified = get_post_modified_time( ‘His’ ); $last_modified = sprintf( __( ‘Last updated %s’, ‘Divi’ ), esc_html( get_post_modified_time( ‘M j, Y’ ) ) … Read more

Get rewrite slug of custom post type in template

You can access the post type properties using get_post_type_object(). The rewrite argument will be a property if the returned object: $post_type_object = get_post_type_object( ‘products’ ); $rewrite_slug = $post_type_object->rewrite[‘slug’]; Update I needed this for permalinks inside a template part where there are categories displayed. No you don’t. To get the URL to a category archive, use … Read more

syntax issue on php 7.4

Option 1 Have you tried changing the function name? something similar function getClientFn($function){}? You can keep any name you want. function getClientFn($function){ return ‘\DisplaceTech\Companies\\’ . $function; } function add_clients_metabox(){ $screens = [‘page’]; foreach ($screens as $screen) { add_meta_box( ‘clients’, // Unique ID __(‘Clients’), // Box title getClientFn(‘clients_box_html’), // Content callback, must be of type callable … Read more

get_the_terms – only top level

Just have a quick test and seems both methods working well. // @Rup’s method $terms = get_the_terms(get_the_ID(), ‘my_taxonomy’); if (!is_wp_error($terms) && !empty($terms)) { foreach ($terms as $term) { // skip if parent > 0 if( $term->parent ) continue; $name = $term->name; $link = add_query_arg(‘fwp_typ’, FWP()->helper->safe_value($term->slug), ‘https://www.freuciv.com/’); echo “<a href=”https://wordpress.stackexchange.com/questions/366690/$link”>$name</a><br />”; } } or $terms = … Read more

How to convert objects into arrays

$wpdb->get_results has a second parameter that lets you specify what kind of return value you want: For example: $data = $wpdb->get_results( $query, ARRAY_A ); Here you get an associative array back.

Custom php page outside the scope of my theme

is this not something that you could put into your functions.php file as a new function, adding the action to init to fire off on the page load? You could then put in an if statement so it only runs when specific criteria is met, such as a page ID or slug or template is … Read more