Permalink for PDF of article

Using add_rewrite_endpoint <?php if ( ! class_exists( ‘PDFRewriteEndpoint’ ) ): class PDFRewriteEndpoint { /** * Add actions and filters in constructor. */ public function __construct() { add_action( ‘parse_request’, array ( $this, ‘sniff_requests’ ), 0 ); add_action( ‘init’, array ( $this, ‘add_endpoint’ ), 0 ); } /** * Add rewrite rules. */ public function add_endpoint() { … Read more

Showing categories and subcategories with posts

Update: Complete code <ul> <?php $get_parent_cats = array( ‘parent’ => ‘0’ //get top level categories only ); $all_categories = get_categories( $get_parent_cats );//get parent categories foreach( $all_categories as $single_category ){ //for each category, get the ID $catID = $single_category->cat_ID; echo ‘<li><a href=”https://wordpress.stackexchange.com/questions/270176/” . get_category_link( $catID ) . “https://wordpress.stackexchange.com/questions/270176/”>’ . $single_category->name . ‘</a>’; //category name & link … Read more

`get_terms()` with `child_of` and `childless` combined

OK, so this is what I came up with: function get_childless_term_children( $parent_id, $taxonomy ) { // get all childless $terms of this $taxonomy $terms = get_terms(array( ‘taxonomy’ => $taxonomy, ‘childless’ => true, )); foreach( $terms as $key => $term ) { // remove $terms that aren’t descendants (= children) of $parent_id if( !in_array( $parent_id, get_ancestors( … Read more

Better wordpress attachment query than this

I don’t have the data to test so the code below may be wrong. add_filter(‘posts_search’, ‘set_is_tax_to_true’ ,10,2); function set_is_tax_to_true($search,$query){ $query->is_tax = true; } $args = array( ‘post_type’ => ‘attachment’, ‘posts_per_page’ => -1, ‘post_status’ => ‘pending’, ‘post_parent’ => $post_id, ‘order’ => ‘ASC’, ‘orderby’ => ‘ID’, ‘meta_query’=> array( array( ‘key’ => ‘cp_sys_expire_date’, ‘value’ => current_time(‘mysql’), ‘compare’ => … Read more

is_child() function

/** * Return whether the current page is a child of $id * * Note: this function must be run after the `wp` hook. * Otherwise, the WP_Post object is not set up, and * is_page() will return false. * * @param int $id The post ID of the parent page * @return bool Whether … Read more

Category shows only top level child categories

‘depth’ is not a parameter for the function get_categories(); to get only direct child categories, try working with ‘parent’ instead of ‘child_of’ https://developer.wordpress.org/reference/functions/get_categories/ https://developer.wordpress.org/reference/functions/get_terms/

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)