Trying to sort and display categories(not posts) by custom field: 'order'

I'm a WordPress rookie. I've added a custom field to my "Category" taxonomy. The custom field is "custom_order" and its purpose is to hold a number so that my categories can be sorted and displayed in the order I choose. My problem is that I can't get them to sort; I can display the categories, and 'echo' each category's "custom_order" number, but I must be missing something when it comes to accessing and sorting the meta_value. Not sure if I'm …
Category: Web

ACF Relationship - Get Parent's Post Object

I've a few post that have ACF relationship field set up : - Post A - Post A1 - Post A2 - Post A3 Post A have a relationship that link to : Post A1,A2 & A3... Post A1,A2,A3 have their own post templates, But inside the post templates, can I manage to get Post A's Title? Because I don't want hardcoded Post A's title on Post A1,A2,A3's fields. I'd tried this solution, but seems can't retrieve parent A's post …
Category: Web

How to save template data into wp_post table (post_content column)

Is there a way to save template data into wp_post table? I made a custom template that automatically makes tables and some sentences with the meta-data that users insert in. I wanted to make users choose a template and write in a standardized format with custom field. Users can now just put some text on my custom field (bottom of my post edit page) and click the template on the sidebar, then the contents show on the post page! And …
Category: Web

how to filter upper and lower case characters in Auto tag link code?

Question: How to filter uppercase and lowercase when the word 'tag' is written in lowercase? and vice versa, how to filter the word 'tag' which is written in capital letters? Here's the code I got from a plugin that hasn't been updated in a few years. function auto_link_tags($content){ //$post_id = get_the_ID(); $post_tags = get_the_tags(); if ($post_tags) { $i = 0; foreach($post_tags as $tag) { $tags[$i] = "~<(?:a\\s.*?</a>|[^>]+>)(*SKIP)(*FAIL)|\\b(?:\\b(" . $tag->name . ")\\b(?=[^>]*(<|$)))\\b~i"; $tag_url = get_tag_link($tag->term_id); $tag_html[$i] = '<a href="' . $tag_url …
Category: Web

Query multiple post types, but different order for each

I have a query which searches 2 post types as below: $args = array( 'post_type' => ['post', 'promotion'], 'posts_per_page' => 12, 'paged' => $paged, 's' => isset($_GET['search']) ? $_GET['search'] : '', ); This orders them by default, by published date. I need to add a third post type events. This however needs to be sorted by a custom field event_date asc and to disregard those which the event_date is in the past. Does anyone have any suggestions on how this …
Category: Web

how to scraping website data to wordpress taxonomy

i want to scrape data from another website that doesn't provide api to my wordpress site, and i want when i input the data url ($baseTarget) it appears directly in the taxonomy input post_tags, title description, category, image etc in new post. i don't know how to make it, i have searched but haven't found any results. scrape.php <?php namespace App\Services; use voku\helper\HtmlDomParser; class MALService { private $baseTarget = 'https://myanimelist.net'; private function init($path) { $curl = curl_init($this->baseTarget . $path); curl_setopt($curl, …
Category: Web

How to "group" (categorize) the Pages together?

I have a lot of Pages which can be (need to be) grouped under a number of different Categories. ** Then the more important thing is, i need to control those pages (of different groups) programatically via functions.php. Lets say, i would have: Page A (Categorized as: Fruits) Page B (Categorized as: Vehicles) Page C (Categorized as: Vehicles) Page D (Categorized as: Fruits) Page E (Categorized as: Technology) Then from functions.php, there would be some logics, like: If Page is …
Category: Web

Add image to menu item with ACF

I'm trying to add an image to menu item, can't get it to work. Here is my code. header.php <?php wp_nav_menu( array( 'theme_location' => 'side-menu', 'container_class' => 'fixed-menu', 'fallback_cb' => '', 'link_before' => '<span>', 'lnk_after' => '</span>', 'depth' => 2, 'walker' => new Understrap_WP_Bootstrap_Navwalker(), ) ); ?> And here is the function.php // Header Side Menu function etm_side_menu() { register_nav_menu('side-menu',__( 'Header Side Menu' )); } add_action( 'init', 'etm_side_menu' ); add_filter('wp_nav_menu_objects', 'wp_nav_menu_objects', 10, 2); function wp_nav_menu_objects( $items, $args ) { // …
Category: Web

Compare ACF date field (if exists) and post date and order DESC

I have an ACF date field (same format as post date) and in my Query I want it to be compared to the publish date of the post: If erstelldatum is not empty use erstelldatum for order If erstelldatum is empty use publish date for order instead Order descending My code is working so far but the order isn`t right. It lists all posts with erstelldatum first followed by those without. I want them to be ordered descending by the …
Category: Web

Bulk Update Custom Fields for Custom Post Types

I am using this function which works great in case anyone wants to bulk update custom fields for custom post types (just change parameters as necessary). $args=array( 'posts_per_page' => -1, 'post_type' => 'mycptype' ); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); $testa = get_field('br_type'); $testb = get_field('br_category'); if ($testa === 'Apples') { update_field('br_featured', '0', get_the_ID()); } endwhile; wp_reset_postdata(); endif; How to use: Insert the code inside your functions.php and refresh …
Category: Web

meta_query 'compare' => '!=' not working

I am using a custom post-type, in post there are a checkbox meta field for featured post. So there are two scenarios. First with featured posts Second with non featured When I called featured posts with meta_query its result 100% perfect. Here is my code: $c_clients_args = array( 'post_type' => 'clients_testimonials', 'posts_per_page' => 6, 'order' => 'ASC', 'meta_query' => array( array( 'key' => 'c_client_feature', 'value' => 'on' ) ) ); $c_clients_result = new WP_Query($c_clients_args); if($c_clients_result->have_posts()) : while($c_clients_result->have_posts()) : $c_clients_result->the_post(); // …
Category: Web

Create custom query for search?

I have create search box using ajax.If i enter any value in search input box that this value search in post title or post meta data and get all data of this value in custom post type.also query check only post title and specific post meta data. Not check in Post content or any other field. I have tried this query $args = array( 's' => $keyword, 'numberposts' => -1, 'post_type' => 'store', 'meta_query' => array( 'relation' => 'OR', array( …
Category: Web

How to use thumbnail size of image if I'm only using src to get image

I have a custom field for an image, and using it this way: <?php $item_img = get_sub_field('image'); ?> <img src="<?php echo $item_img ?>" /> But I want to use the thumbnail version of the image, as set to 150x150 in wordpress. How do I do that with this type of setup? Do I have to set a custom add_image_size() or does wordpress have duplicated thumbmail size images?
Category: Web

Found 2 elements with non-unique id (#_ajax_nonce) and (#_wpnonce)

I am developing custom theme from scratch and creates a custom post type and getting this warning while editing custom post type. I also design custom Meta box with two input fields and using nonce in it. Any help removing these warning? Here is code of custom metabox in functions.php //Custom Metabox function register_book_meta_box(){ add_meta_box('book_meta_box_id', 'Book Detail','design_book_meta_box','books','advanced','high'); } add_action('add_meta_boxes','register_book_meta_box'); function design_book_meta_box($post){ wp_nonce_field(basename(__FILE__),'book_cpt_nonce') ?> <div> <label for="book-author">Author Name  </label> <input type="text" name="book-author" placeholder="Author Name" value="<?php echo get_post_meta( $post->ID, 'book-author-key', true );?>"> </div> …
Category: Web

Change post format using custom field

I'm creating a theme using the CF Post Formats plugin. But I've run into some trouble I don't know how to solve. Here's what I want to be able to do: Create a new standard-format post Enter a url into the _format_link_url custom field If the custom field is not empty, on save/update, change the post format to 'link'; else, remain 'standard'. For whatever reason, I can't get set_post_format to work in this context (perhaps there's a conflicting update?). I …
Category: Web

Hide custom fields by user's role

I've tried reading all the questions about this topic, and configured the code to fit my needs, but can't seem to get it to work. This is the code I have now: function my_exclude_custom_fields( $protected, $meta_key, $user ) { $user = wp_get_current_user(); if ( in_array( 'udlejer', (array) $user->roles ) ) { if ( in_array( $meta_key, array( 'email', 'text' ) ) ) { return true; } } return $protected; } add_filter( 'is_protected_meta', 'my_exclude_custom_fields', 10, 2 ); It doesn't make any change. …
Category: Web

Output Custom Field value to shortcode

I am trying to automate a whole bulk of my pages and one of the shortcodes I have created is to output the NextGen Gallery Tags by using the page custom fields that each page has a unique id. This id is actually tagged into certain galleries which I want to output on the page. For those unfamiliar with NextGen Gallery tags shortcode. Please visit this link. Each page has a custom field "gallery_id" which I input a unique tagged …
Category: Web

Sort categories by meta value

How can I make a list of categories with 4 last posts in each where every category is sorted by meta_value. For example, template without sorting by meta_value is http://pastebin.com/AeH6vx9b It displays parent categories only. Few days I am searching something related to categories extra fields but can't find something workable. This is my best search result. What I have to do with this? I don't understand it. Is it possible to do what I want?
Category: Web

set and unset the custom field value

While showing all the posts together in admin panel, I have a custom column 'Featured Image'. And this column has a value YesOrNO. To set the column name : I have inside functions.php: function set_column_heading($defaults) { $defaults['featured_image'] = 'Featured Image'; return $defaults; } add_filter('manage_posts_columns', 'set_column_heading'); In order to set the column value, I have : function set_column_value($column_name, $post_ID) { if ($column_name == 'featured_image') { $post_featured_image = get_featured_image($post_ID); if ($post_featured_image) { echo 'YesOrNO'; } } } function get_featured_image($post_ID) { $post_thumbnail_id = …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.