New answers tagged

0

Wordpress features a very robust template hierarchy that should be observed, take a look at wphierarchy.com. If you needed two header formats for some reason, you could create a file in the theme root called header-manga.php which you could then call in your page template with <?php get_header( 'manga' ); ?>. Once you have your new header set-up you ...


1

You don't need the rewrite rules, and that's not how they'd work anyway. The fundamental problem is that you decided not to modify the main query, but to replace it. There's no need for the custom WP_Query or custom pagination, or a page template. Not to mention by running the main query then discarding the result to make a new one, it doubled the amount of ...


0

You don't need to do any of that, and can sidestep the problem completely, and make the code faster and simpler! This is what we're going to do: We're going to use the course post author, not the name, it's more reliable We're going to avoid the raw SQL query so we can use caches and use WP_Query We'll use wp_insert_post for both updating and creating the ...


0

Perhaps you're looking for is_singular, which you could put in e.g. your theme or functions.php to test for your CPT like: if (is_singular('anime')) { wp_enqueue_style( ... ) ; }


0

You can use conditionals: <?php add_action( 'wp_enqueue_scripts', 'wpse_enqueues' ); function wpse_enqueues() { // Only enqueue on specified single CPTs if( is_singular( array( 'anime', 'manga' ) ) ) { wp_enqueue_style( 'wp-manga-plugin-css', WP_MANGA_URI . 'assets/css/style.css' ); } } ?> If you need the CSS on archives as well, ...


0

found the solution the problem was the "posts_per_page" it made my website crash on that specific section and also in wp-config.php added define( 'WP_MEMORY_LIMIT', '256M' ); and it solved my problem


1

I think it would be helpful if you could explain why you're generating courses out of edits that a user's doing on his profile. The simplest solution seems to be a frontend form that just allows a user to create new posts or edit existing ones rather than going for this alternative solution where you're using the data from the profile page to create new ...


0

Here's a more polished solution ;) Fix TinyMce error Add form submit event listener. Hide spinner after complete request and enable save button again. Also i make it shorter for easy to use :) just put this code in your functions.php: <?php // Saving the post via AJAX add_action( 'save_post', function ( $post_id ) { # Ignore autosaves if ( ...


0

it was completely my bad. I am using this plugin and I updated my functions.php file but the plugin wasn't activated although I thought it had been. Extension is here & it works in 5.4.2 with Gutenberg blocks if anybody is intereested: https://github.com/jchristopher/attachments


0

Make following changes in custompage.php file <?php $paged = ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : 1; $args = array('post_type'=>'salmi','posts_per_page' => 15,'paged' => $paged); $the_query = new WP_Query($args); if ( $the_query->have_posts() ): while ( $the_query->have_posts() ) : $the_query->the_post(); ?> ...


0

Solution is to check for post_tag taxonomy existence. public function getPostTypes() { $excludes = array('attachment'); $getPostTypes = array_values( get_post_types( array( 'public' => true, ), 'names' ...


0

Please try this. function get_post_tp(){ $args = array( 'public' => true, '_builtin' => false, ); $post_types = get_post_types( $args, 'objects' ); foreach ( $post_types as $key => $value ) { $postArray = json_decode(json_encode($post_types), true); $array_key = key($postArray); print_r($post_types[$array_key]->taxonomies);...


0

You can avoid needing to test for the post type in the save_post action by using save_post_{post_type} E.g. add_action( 'save_post_portfolio', ..... Where portfolio is the post type being saved. Using save_post will run your code for all posts types unless explicitly checked.


0

add_action( 'save_post', ... and test if your post type is tour custom post type.


0

When registering the custom post types, set with_front to false: register_post_type( 'my_post_type', [ // ...etc. 'rewrite' => [ 'with_front' => false, ], ] ); The post type URL will then not include anything extra you've added in the Permalinks settings.


1

You may have already figured this one out, but here's two examples how to do this. In both of my examples I do the sorting first and rendering second. This keeps things cleaner and clearer in my opinion. Example 1 Loop queried posts and sort them into two helper arrays. If those arrays have posts, loop them through and render posts. $posts = ...


1

Considering you mention having registered a custom taxonomy instead of using the native tags, the functions the_tags() and get_tags will not work. you need to get your custom taxonomy terms by using get_the terms(). Usage is not much different from using native tags, but you have to pass the post_type as a variable. See the Wordpress codex on this: https://...


1

ACF has the ability to create a 'Theme Options' page which you can then use to conveniently centralise options for things like headers and footer etc.. ACF Options Page information As Jacob Peattie rightly points out, how you integrate this into Gatsby is outside of the scope of WPSE and may require custom development. However, providing you can inject ...


1

Have you considered changing them to Categories? Categories and Tags are essentially the same thing, just that Categories have a Hierarchy. Category selection is via a Checkbox so you will have more control over what is selected. Update If you have used the function 'register_taxonomy' to create your Tags then you only need to add or adjust one variable - '...


1

You could filter the the_post_thumbnail() function, which will dynamically show the assigned category image across all your custom post type, rather than using acf_save_post to save the category image in the post featured image meta field. By filtering the the_post_thumbnail() for your specific post type, this means if you change the image on category in the ...


1

As well as the answer from TheRecruit referencing the ACF plugin, you should also consider how your data is structured in terms of Categories, Tags etc as opposed to fields in individual posts. Another useful plugin is therefore CPT UI, which gives a nice, graphical interface to creating custom post types and taxonomies. So for instance you might use CPT UI ...


0

For multiple Custom Post Types adjust like this $query->set( 'post_type', array( 'post', 'custom1', 'page' ) && array( 'post', 'custom2', 'page' ) );


0

I don't think you've provided enough information to give you a clear answer. Perhaps explain what you are doing when you Update the post - are you changing something first? And - is this a task you only need to do once, or will you need to do it regularly? Wordpress doesn't have Custom Post Types by default - thats why they are called 'Custom'. So your ...


0

Here we showing an example to relative displaying custom post type in WordPress and in this code have args in arrays and using wp_query with the loop for getting post data. $args = array( 'post_status' => 'publish', 'posts_per_page' => 5, ); $loop = new WP_Query( $args ); while ( $loop->have_posts() ) : $loop->the_post(...


2

Unless you're eager to program the functionality yourself, I would highly recommend "Advanced Custom Fields" (a plugin). It's very intuitive, and gives you the ability to add custom fields (duh!) to every post-type in your theme. This means that I could add a "Height"-field above my WYSIWIG-editor in my Post-editor.


0

So I can't give you a complete solution but here are the pieces that I think might help: Getting parent post ID: wp_get_post_parent_id() - https://developer.wordpress.org/reference/functions/wp_get_post_parent_id/ Getting all posts with a particular parent ID. Here's a WP_Query args to get all posts by parent ID $args = array( 'post_parent' =&...


0

There is a typo: Use below statement under save_appointment function //indexes are case sensitive, note the capital 'D' $aptDate = wp_strip_all_tags($_POST["aptDate"]); instead of $aptDate = wp_strip_all_tags($_POST["aptdate"]);


1

As Jacob Peattie pointed out in this comment, the reason why you code isn't working is because you have two functions with same name create_posttype. PHP assumes you want to re-declare the function, which you cannot do. So in order for your code to work, you can either combine your custom post types creation into one function (as Jacob suggests): // Our ...


0

There isn't an order or numbering of posts like this that is stored in Wordpress. The database stores things with a 'primary key', which is just a number, but this always stays the same for each post, forever. So if you add lots of posts and remove lots of posts then add some more, the Primary Key for the first 3 posts might be 1,20,100. If you want to find ...


0

I've had this problem also, even while avoiding $_POST[] This hook appears to be overall quite buggy. You can see from this GitHub thread a discussion about how the transition_post_status hook gets called twice for every post status update: https://github.com/WordPress/gutenberg/issues/15094 The problems I faced were: if/conditions not working within the ...


0

Apart from any other errors that might be in your code that some others have pointed out, I've found that accessing attributes defined as "meta" from the save function has issues. I've posted my own question about it here. and a bug report about it here. Essentially, while the documentation says "meta attributes can be read and written by a ...


0

first you need to loop how many times repeater has values example anada_number_0_anada_number anada_number_1_anada_number anada_number_2_anada_number In my case i have five times repeater field for( $i=0; $i<5; $i++ ){ $meta_query['anada_number'][] = array( 'key' => 'anada_number_'.$i.'_anada_number', 'value' => $...


1

This is somewhat opinion based answer, and is specific to SEO, not necessarily Wordpress. Generally a URL should refer to a specific entity, and a/b/c often implies a relationship between a/b/c like b is a parent or container of c, a is a parent or container of b. So it doesn't make much sense that a/b/c, b/a/c and x/y/c all reference the same thing. SEO ...


1

get_permalink() (which is used by get_the_permalink() and the_permalink()) returns the "ugly" URL if the post is not published, e.g. draft or scheduled, but you can use the following function instead which temporarily sets the post status to publish so that we'd get the pretty URL. function get_future_permalink( $id ) { if ( $post = get_post( $...


0

It's solved now - apparently, the theme developer didn't put in the call for the above template in the single project template in the latest update... I'm not sure if it's intentional or just an oversight, but it took a while to find the right template to change. All good now!


0

Solution 1 (not a good idea): add_users_page( _x( $this->page_title, "page_title", $this->text_domain ), _x( $this->menu_title, "menu_title", $this->text_domain ), $this->capability, "edit.php?post_type=my-post-type" ); Notice : This code is used in a class. When you are on the page, it can have ...


1

When you register the CPT, use the rewrite argument to add the prefix. For example if your CPT is currently registered like this: <?php function wpse_create_cpt_testimonial() { $args = array( 'public' => true, 'label' => __( 'Testimonials', 'textdomain' ), // ... you probably have other arguments as well ); ...


2

A little more time searching around, and I found the answer... here it is in case it helps anyone else. In the function that creates the custom post type, I added this: $rewrite = array( 'slug' => 'results/testimonials', 'with_front' => true, 'pages' => true, 'feeds' =>...


2

If you want to do it from WordPress environment itself.. function wpse370481_redirect_url() { if ( is_singular( 'resources' ) ) { global $post; $path = $post->post_name; $redirect_url = 'https://materials.domain.com/' . $path; wp_redirect( $redirect_url ); exit; } } ...


1

You need to get the term object first. //Your meta field $post_custom_title = get_post_meta($post_id,'car_name',true); //Get the term object by id. change taxonomy_slug to the taxonomy you intend to use $term = get_term_by( 'id', $post_custom_title, 'taxonomy_slug' ); //Retrive the term name and use it as post title $term_name = $term->name; //call the ...


0

This work for me, kindly try it, Thanks Templates is loaded into cpt file, which was located at custom_plugin -> app -> cpt -> cpt_article.php Template is located custom_plugin -> app -> templates add_filter( 'single_template', 'load_my_custom_template', 99, 1 ); function load_custom_templates($single_template) { global $post; if ($post-...


1

Managed to get it working with the following code: <?php $terms = wp_get_object_terms($post->ID, 'product_category'); if(!empty($terms)){ foreach($terms as $term){ $exampleName = $term->name; $exampleSlugs[] = $term->slug; $category_colour_primary = get_field('category_colour_primary', $term); $category_colour_secondary = ...


0

$terms = get_terms('CUSTOM_TAXONOMY', ['hide_empty' => true]); foreach( $terms as $term ){ echo '<section>'; echo '<h1>' . $term->name . '</h1>'; $posts = get_posts([ 'post_type' => 'CUSTOM_POST_TYPE' 'tax_query' => [ [ 'taxonomy' => 'CUSTOM_TAXONOMY', '...


1

I would try something like this... // Assume there is only one category. $product_category = get_the_terms($post, 'product-category')[0]; $cat_fields = get_fields("term_$product_category"); $color = $cat_fields['category_colour_primary']; You could also do this... // Assume there is only one category. $product_category = get_the_terms($post, '...


0

The default WP category is only set-up to show posts out of the box. You should be able to expand this by doing something like the below in your functions.php: // Order course archive and taxonomy views function adjust_main_query($query){ if ( ! is_admin() && is_category() && is_category() && $query->is_main_query() ) { ...


0

Your code is correct. Your problem in the timing of executing both: Registering the CPT Calling the post type function you wrote. You have one of 2 solution: Solution 1: Make sure your CPT is registered with higher priority before calling the get_post_types function. Solution 2: Reduce the get_post_types priority to start after CPT is registered. ...


4

Sometimes this would be achievable with add_rewrite_url but it looks like in this case it's not as you need to redirect to a different domain. In this case you need .htaccess or nginx rules to do this, so you need to add something like this to your nginx config for domain.com only, in order to rewrite those URLs: rewrite ^/resources/(.+) https://materials....


1

The correct link should look like this: /wp-admin/edit.php?{taxonomy_slug}={term_slug}&post_type={cpt_slug} For example. If you have taxonomy brand and it has term (category) test, your link will be: /wp-admin/edit.php?brand=test&post_type=CPT


Top 50 recent answers are included