Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

New answers tagged

1

This question is a follow up of this question you asked earlier. Here we handled getting count per posttype. So you have all data, just not sorted correctly. Looking at your code you have one big problem. Getting and formatting data is done at the same time as you are outputting the data. For maintainability (and readability) it is best to separate these as ...


0

Thanks for posting that additional information. I think I understand what you're trying to accomplish now. Instead of filtering the value like you are now, all you have to do is update the field value during the migration. update_field($selector, $value, $post_id); Learn more about updating ACF field data.


0

I was able to fix it by using this function add_action( 'series_add_form_fields', 'sermon_series_add_details', 10, 2 ); instead of this: add_action('add_meta_boxes','add_Book_series_metabox');


0

I have developed functionality which is check duplicate value for specific post meta value exist or not on update post. when user update data and if find any record then give a error message in admin dashboard(see attached screenshot). you can use below code according your requirement. class Check_duplicate_entry { public function __construct(){ ...


0

So I tried everything and every plugin to fix my issue and expose the list CPT data instead of showing brackets [ ]. And the answer is something that might be a bug in Wordpress Rest API. The problem was I am using custom statuses and none of my posts were assigned as default Wordpress status. After changing the posts to any of the default built-in ...


0

I think all you'd need to do is change the WP_Query from $catquery = new WP_Query( 'cat=' .$category_id. '&posts_per_page=100' ); to $catquery = new WP_Query( 'post_type=property&posts_per_page=100' ); This assumes your new custom post type is registered as "property" (lowercase) - if you registered the new post type using 'Property' or '...


1

That filter is actually dynamic, so you'll just need to append your post type: add_filter( 'rest_prepare_projects', 'chrest_adjacent_posts', 10, 3 ); https://github.com/WP-API/WP-API/blob/develop/lib/endpoints/class-wp-rest-posts-controller.php#L1355 Hope that helps!!!


0

Your can use post_parent parameter for your query. Ref: https://codex.wordpress.org/Class_Reference/WP_Query This will change your query to: $args = array( 'post_type' => 'b_books', 'order' => 'ASC', 'orderby' => 'date', 'posts_per_page' => 10, 'post_parent' => 0 ); genesis_custom_loop( $args );


1

What makes this annoying is that the count is a wp_term_taxonomy table. So the way to do this is a custom query: function wpse340250_term_count( WP_Term $term, $post_type) { $q_args = [ 'post_type' => $post_type, 'nopaging' => true, // no limit, pagination 'fields' => 'ids', // only return post id's instead of full ...


0

1st. you need to add post_type to your query, then you need to filter meta_value with LIKE. Finaly, you need to add posts_per_page as -1 to get ALL posts. $args = array( 'post_type'=> 'books', 'meta_query' => array( array( 'key' => 'book_type', 'value' => 'Fiction'...


0

What you are looking for is custom taxonomy (which has been mentioned in the comments). Which you create with the register_taxonomy() function. There is a beginners guide here if you need it. You will need to pass in an array of arguments. The most important is probably hierarchical which is true for something like categories, or false for something like ...


0

Disclaimer: I have not tested this out myself. It looks like you will have to hook the calendar and push your content into it. The filter that gets called by the calendar is get_calendar. So, at a guess, something like this: function filter_get_calendar( $cache_key ) { // Do awesome things here... return $cache_key; }; // add the filter ...


0

I finally get this done: <?php $taxonomies = get_object_taxonomies( $post, 'objects' ); foreach ( $taxonomies as $taxonomy ) { $tax_name = $taxonomy->labels->singular_name; the_terms( $post->ID, $taxonomy->name, '<span class="e-article__category__item"><strong>' . $tax_name . ': </strong> ', ", ", '</span>' ); } ?> ...


0

As far as I'm aware, your question has been answered here. You're getting the singular_name correctly, all you need to do is echo it. <?php $taxonomies = get_object_taxonomies( $post ); foreach ( $taxonomies as $taxonomy ) { $term_name = $taxonomy->labels->singular_name; echo $term_name; the_terms( $post->ID, $taxonomy, '<span class="e-...


0

I was getting the same fatal error after creating a similar dynamic menu. What fixed the issue for me was redefining the default values: $post->target = ''; $post->attr_title = ''; $post->description = ''; $post->classes = ''; $post->xfn = ''; $post->status = 'publish'; $post->original_title = ''; So your foreach loop would look like ...


1

I think I am understanding your correctly...If I'm way off, let me know! // Assuming ideas is an array and you are looking for ideas=>two $query = new WP_Query( array( // You can pass 'any' to post_type, but you get a hold of revisions, attachments, and menu_items. But I am not sure how many Custom Post Types you have ¯\_(ツ)_/¯ '...


0

The problem is caused by flush_rewrite_rules(). Remove that line and the issue should be resolved. If you call that function on every page load it can cause issues like this with permalinks. This function should only be run once after your theme or plugin is activated (but not on the activation hook, since that's too early). This is because permalinks are ...


0

There's no such page in WordPress. /issues/ doesn't exist. All WordPress URLs display either a single post/page, or a list of posts/pages (search, date archives, category archives etc.). So there's no way WordPress will list terms. If you create a new issue, then that will be accessible at /issues/issue-name/, but nothing will exist on /issues/ by itself. ...


1

You need to update below line at where you have register a custom post type using register_post_type function. 'rewrite' => array('slug' => 'courses/%cat%') To change permalink dynamically of post type you have to add below code in functions.php file : function change_link( $post_link, $id = 0 ) { $post = get_post( $id ); if( $post->post_type ==...


0

You need to update below line at where you have register a custom post type using register_post_type function. 'rewrite' => array('slug' => 'teachers/%cat%') To change permalink dynamically of post type you have to add below code in functions.php file : function change_link( $post_link, $id = 0 ) { $post = get_post( $id ); if ( is_object( $...


0

In its current form, your meta_query is overwritten in each iteration. In the final effect, you have only one custom field in meta_query: Depending on the operator you want to use, meta_query argument should look as follow: for "LIKE", "REGEXP" if( is_array($keywords) && count($keywords) ) { $args['meta_query'] = array( 'relation' => 'OR' )...


-1

Okay so the solution was just adding this code to the $args 'has_archive' => 'companies',


0

With the new WordPress admin area "show_in_rest" must be set to true for custom taxonomies to show up in page editor.


0

You can get the taxonomies that are registered for a post type with get_object_taxonomies(). If you pass the post object directly, you don't even need to explicitly name the post type either. You can then loop through the result of that function to achieve the result you want: $taxonomies = get_object_taxonomies( $post ); foreach ( $taxonomies as $...


0

Have you tried passing an array of values to the value argument? $your_terms = array( 'foo', 'bar', 'baz' ); $args['meta_query'] = array( 'relation' => 'OR', array( 'key' => 'customfields', 'value' => $your_terms, 'compare' => 'REGEXP' ) ); $this_query = new WP_Query( $args );


2

The problem is that you've set the value for 'public' incorrectly. That argument is a boolean, meaning it's true or false, and in PHP these need to be written without quotes to be correct: register_post_type( 'magazine', array( 'labels' => array( 'name' => 'magazine', ), 'public' => true, ) ); ...


0

You can use wp_query() for this to work $args = array( 'post_type' => 'auction', 'posts_per_page' => -1, ) $query = new WP_Query($args); if ($query->have_posts() ) : echo '<select>'; while ( $query->have_posts() ) : $query->the_post(); echo '<option value="' . get_the_ID() . '">' . ...


1

If you need to get tags by post id you could use the followng function. This will work on anywhere since the method is based on database querying. function sc_tf_get_tags_as_array($post_id){ global $wpdb; $tbl_terms = $wpdb->prefix . "terms"; $tbl_term_relationships = $wpdb->prefix . "term_relationships"; $sql = "...


-1

This is very simple to do. Create a new PHP file in your theme root directory and add this to the top: <?php /* * Template Name: My custom view * Template Post Type: Post_typename // here you need to add the name of your custom post type */ ?> Full example will be as following: <?php /* * Template Name: My custom view * Template Post ...


0

Since 4.7 Custom Post Types have supported custom templates, just like Pages. So you could copy your theme's generic page template to a new template file, and add this to the top. <?php /* Template Name: Block editor template Template Post Type: my-post-type */ That will let you switch the template for your my-post-type post to a template that looks and ...


1

You can create taxonomy-cat-cpt.php, and inside it just use: <?php get_template_part( 'archive-cpt' ); ?> Then they'll both use the same template. Then inside archive-cpt.php, if you use the_archive_title() archive the_archive_description() it will display the appropriate title and description automatically based on whether you're viewing the ...


0

Emojis are characters. It's probably not what you're looking for but you could potentially paste emojis in the character field. Your other option would be to create font somewhere like Glypther, install it on the site and the use CSS to assign the font to you category titles and use the related letters for the icons you want. That route would take some ...


2

Your 3rd option is correct. $args3 = array( 'posts_per_page' => 9, 'orderby' => 'date', 'order' => 'DESC', // If you're only specifying one. Use array( 'projects', 'post' ); for many. 'post_type' => 'projects', // This is the correct syntax for a taxonomy query. 'tax_query' => array( ...


0

That would be achieved using the wp_set_post_terms function. https://codex.wordpress.org/Function_Reference/wp_set_post_terms You could run an ajax request on the change event of the dropdown to either wp-admin/admin-ajax.php or a custom JSON API endpoint (preferred but more work) with a payload like this { new_status: 123 post_id: 321 } Ensure ...


1

You can use one of the status transition filter hooks for this: {$new_status}_{$post_type} transition_post_status In the function assigned to the hook, you change the status to publish the previously featured post ( using e.g. $wpdb ). Both actions are performed after saving the post, so you have to change the status in posts other than edited. ...


0

You can use 'type' => 'DECIMAL(10, 2)', in meta query. It is mentioned in the documentation Custom_Field_Parameters.


0

You could use these plugins: https://wordpress.org/plugins/custom-sidebars/ https://jetpack.com/support/widget-visibility/ Both allow you to control which widgets/sidebars show up where.


0

Solution: Shadow Taxonomy Lib https://github.com/mrbobbybryant/shadow-taxonomy This looks like a robust solution for this issue and including wp cli support for creating, deleting, and evaluating the linkages. I haven't test it yet but it seems like the perfect solution for this issue.


0

I 've got similar issue, global $post was null on free theme (astrid) after struggling I disable Yoast SEO and its works. So I update Yoast SEO and works with. But to be honest I will change Yoast by something else cause Im getting to much trouble with this plugin. Hope its help :-) EDIT : After multiple tests, Im not sure the issue comes from Yoast (but ...


0

Why not create your own custom post display block using this easy to use plugin lazyblock https://wordpress.org/plugins/lazy-blocks/ ? Simple steps are here, first create your custom loop using wp_query, you can take help of https://generatewp.com/wp_query/ here is my custom loop for portfolio post type I had created // WP_Query arguments $args = array( ...


0

For fixing custom post not found (404 issue) please use below code in your functions.php: flush_rewrite_rules( false ); Please let me know the result so i can help you out further.


0

Your code is working perfectly. You have to refresh/flush permalinks after creating "Custom Post Type" hook. Step 1: In the main menu find "Settings > Permalinks". Step 2: Scroll down if needed and click "Save Changes". Step 3: Rewrite rules and permalinks are flushed.


0

The $field variable isn't available inside your get_callback() function. PHP isn't like JavaScript in that way, and that function can't access variables from outside its scope (unless it's global, but that's a poor solution). To pass the $field variable through to the callback function, you need to write it like this: 'get_callback' => function() use ( $...


0

The way you are customizing the query you are telling it to search for posts that ALSO match a custom tax_query criteria. This would never work, logically speaking. You said, "I want it to return a result if this tag is searched or if it matches the title" for which I understand ONE or ANOTHER. I'll show you a completely different approach, using basically ...


0

I am guessing that you are searching for post and if post not found then you want to display page. If you are using WordPress default search then you can try this code function my_cptui_add_post_type_to_search( $query ) { if ( is_admin() || ! $query->is_main_query() ) { return; } if ( $query->is_search() ) { $query->set( '...


0

I think you need to remove $_GET['post_type'] Please use below code i think you might help : add_action( 'pre_get_posts', function ( $q ) { if ( !is_admin() // Only target front end, && $q->is_main_query() // Only target the main query && $q->is_search() // Only target the search page ) { ...


1

Not exactly what you asked for, but given that classes are primarily used for styling, might you consider using CSS pseudo-class ":last-child" instead of PHP code? Here's some information on how to style using :last-child https://css-tricks.com/almanac/selectors/l/last-child/


0

You can not use is_single() conditional tag here. You can check the type of post in the function this way: add_action( 'save_post', 'set_genre_on_save', 20, 3 ); function set_genre_on_save( $post_id, $post, $update ) { if ($post->post_type != 'hvm') return; // ... } You can also attach the function to the action hook save_post_{...


1

It seems WordPress breaks other rewrite rules when you use the character % for rewrite slug of CPTs. Not sure why. Anyway, I got it to work making the following changes in your code. Stop using %. It's not required actually: $rewrite = array( 'slug' => 'sector/service', 'with_front' => false // It has nothing to due with the solution, ...


0

Add this after $args $categories = get_terms('category', $args); //get all categories $count = count($categories ); //count categories if ( $count > 0 ){ //Check if you got some categories foreach ( $categories as $category ) { $args['cat'] = $category->term_id; //get the id of each category and add it as a parameter $loop_our_work = new WP_Query( $...


Top 50 recent answers are included