Save selected item from dropdown menu in a meta box as a metadata value for a custom post type

$myterms = get_terms($taxonomies, $args); returns an array of term objects. Use $term->term_id as option value … “<option value=”$term->term_id”>”. esc_html( $term_name ) . “</option>” … and store that ID, not the name. Names can change, the IDs will stay the same – unless someone deletes a term and creates a new one with the same name. … Read more

tag search using WP_Query

new WP_Query(array(‘tag_slug__in’ => array(‘forrest-gump’, ‘forest-gump’, ‘questend’))); new WP_Query(‘tag=forrest+gump,forest+gump,questend’); should work too…

Replacing a specific menu item

This is relatively easily done using the walker_nav_menu_start_el filter (without all that PHP tag spam): function nav_replace_wpse_189788($item_output, $item) { // var_dump($item_output, $item); if (‘Profile’ == $item->title) { global $my_profile; // no idea what this does? if (is_user_logged_in()) { return ‘<div class=”img” data-key=”profile”>’.get_avatar( get_current_user_id(), 64 ).'</div>’; } } return $item_output; } add_filter(‘walker_nav_menu_start_el’,’nav_replace_wpse_189788′,10,2); Note: I had to … Read more

Retrieving and Displaying Data From a Table

You have this: <li><?php echo $retrieved_data->column_name;?></li> <li><?php echo $retrieved_data->another_column_name;?></li> <li><?php echo $retrieved_data->as_many_columns_as_you_have;?></li> Here, the code tries to output the data in the column_name column, but there is no column in the table by that name. Likewise, there is no another_column_name or as_many_columns_as_you_have columns in your table. We know that the query pulls in the data, … Read more

WP_Query | Help me create a search term with an ‘OR’ relation?

(Revised on March 25 2020 UTC) So in this revised answer, I’ll just begin with the code: Define the variables: (I intentionally included only the $args part) // define POSTed/submitted variables here like $paged, $display_count and $direction // define the offset/’direction’ stuff here // then define your $args array $args = array( ‘post_type’ => ‘product’, … Read more

Shortcode created to check language not works

In a shortcode you always need to return something. It’s also good practice to make your code very logical and readable. Here are a list of PHP Logical Operators: http://php.net/manual/en/language.operators.logical.php Complete List of WordPress Locale Codes: https://wpastra.com/docs/complete-list-wordpress-locale-codes/ Below an example as English as a backup/fallback language: function coupon_shortcode() { $logged_in = is_user_logged_in(); if (get_locale() == … Read more

get image url inside the content in wordpress?

Sounds like you need to do some regular expression on your post content. Which could be done for example like this: // get the post object $post = get_post( get_the_ID() ); // we need just the content $content = $post->post_content; // we need a expression to match things $regex = ‘/src=”https://wordpress.stackexchange.com/questions/162402/([^”]*)”https://wordpress.stackexchange.com/”; // we want all … Read more